CNLiveDownSlideRecommendCell.swift
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// CNLiveDownSlideRecommendCell.swift
// metaCode
//
// Created by zx on 2023/10/20.
// type:4 推荐课程 推荐活动
import Foundation
///推荐课程左间距
let DownSlideRecommendLeftGap: CGFloat = 15
///推荐课程宽高
let DownSlideRecommendWH: CGFloat = (KSreenWidth-DownSlideRecommendLeftGap*3)*0.5
///type5 竖版短剧图片的高
let DownSlideTwoDuanJuImageH: CGFloat = 217/150.0*DownSlideRecommendWH
///type5 竖版短剧图片的宽
let DownSlideTwoDuanJuImageW: CGFloat = (KSreenWidth-DownSlideRecommendLeftGap*5)*0.5
///type5 竖版短剧cell的高
let DownSlideTwoDuanJuH: CGFloat = 15+17+30+15+217/150.0*DownSlideRecommendWH+10+20+3+33+25+10
///type7 实时热榜的高
let DownSlideRealHotListH: CGFloat = CGFloat(DownSlideSingleCourseW*140/345.0)+154
//播放页 实时热榜的高
let DownSlideRealHotListDetaiImgH: CGFloat = CGFloat(KSreenWidth*152/375.0)
let DownSlideRealHotListDetaiCollectCellH: CGFloat = CGFloat(KSreenWidth*154/375.0)
let DownSlideRealHotListDetaiCoverH: CGFloat = CGFloat(KSreenWidth*(152-65)/375.0)//cellectCell盖住图片的高
//实时热榜详情页总高
let DownSlideRealHotListDetaiH: CGFloat = DownSlideRealHotListDetaiImgH+DownSlideRealHotListDetaiCollectCellH-DownSlideRealHotListDetaiCoverH
class CNLiveDownSlideRecommendCell: UITableViewCell {
//slideModel
var _slideModel : CNLiveDownSlideModel?
var slideModel : CNLiveDownSlideModel? {
get{
_slideModel
}
set{
_slideModel = newValue!
setupNewUI(model: _slideModel!)
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
contentView.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
contentView.clipsToBounds = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupNewUI(model:CNLiveDownSlideModel){
//总块数
let contentsNum = model.contents.count
//model行数
let row = model.rowNum
//总显示块数/循环数
var totalNum = (contentsNum >= row*2) ? row*2 : contentsNum
if row == 0{//row为0 , contents全部显示
totalNum = contentsNum
}
//lieIndex 当前是contents的第0列还是第1列
var lieIndex = 0
//hangIndex 当前是第几行,1...n
var hangIndex = 1
for i in 0..<totalNum{//i是第几行
if lieIndex == 0{
//显示左边的块
let contentMdl = model.contents[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(hangIndex-1)*DownSlideRecommendWH+DownSlideRecommendLeftGap*CGFloat(hangIndex-1), CGFloat(DownSlideRecommendWH), CGFloat(DownSlideRecommendWH)))
imageView.kf.setImage(with: URL(string:contentMdl.poster))
imageView.tag = i
imageView.layer.cornerRadius = 14
imageView.clipsToBounds = true
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(pushWebAction)))
contentView.addSubview(imageView)
lieIndex = 1
}else{
//lieIndex==1显示右边的块
let contentMdl = model.contents[(hangIndex-1)*2+(lieIndex)]
let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(DownSlideRecommendWH), CGFloat(hangIndex-1)*DownSlideRecommendWH+DownSlideRecommendLeftGap*CGFloat(hangIndex-1), CGFloat(DownSlideRecommendWH), CGFloat(DownSlideRecommendWH)))
imageView.kf.setImage(with: URL(string:contentMdl.poster))
imageView.tag = i
imageView.layer.cornerRadius = 14
imageView.clipsToBounds = true
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(pushWebAction)))
contentView.addSubview(imageView)
lieIndex = 0
hangIndex += 1
}
}
}
@objc func pushWebAction(ges: UITapGestureRecognizer){
let imageView = ges.view as! UIImageView
let i = imageView.tag
let contentMdl = (self.slideModel?.contents[i])!
CNLiveDownSlideTool.pushWebVCWithContentsMdl(model: contentMdl.model , contentId: contentMdl.contentId , pid: contentMdl.pid , shareUrl: contentMdl.shareUrl , thirdUrl: contentMdl.thirdUrl , title: contentMdl.title , s_to: contentMdl.s_to ,trailerId: contentMdl.trailerId , controller: nil, slideModel: nil)
}
}