CNLiveDownSlideBannerCell.swift 2.75 KB
//
//  CNLiveDownSlideBannerCell.swift
//  metaCode
//
//  Created by zx on 2025/2/7.
//

import Foundation

///banner高度
let DownSlideBannerH: CGFloat = DownSlideBannerW*195/345
///banner宽度
let DownSlideBannerW: CGFloat = KSreenWidth-DownSlideRecommendLeftGap*2

class CNLiveDownSlideBannerCell: UITableViewCell {
    //slideModel
    var _slideModel : CNLiveDownSlideModel?
    var slideModel : CNLiveDownSlideModel? {
        get{
            _slideModel
        }
        set{
            _slideModel = newValue!
            
            for obj in contentView.subviews{
                obj.removeFromSuperview()
            }
            self.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) ? row : contentsNum
        if row == 0{//row为0 , contents全部显示
            totalNum = contentsNum
        }
        for i in 0..<totalNum{//i是第几行
            let contentMdl = model.contents[i]
            let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(i)*(DownSlideBannerH+DownSlideRecommendLeftGap), CGFloat(DownSlideBannerW), CGFloat(DownSlideBannerH)))
            imageView.kf.setImage(with: URL(string:contentMdl.poster ))
            imageView.tag = i
            imageView.layer.cornerRadius = 12
            imageView.clipsToBounds = true
            imageView.isUserInteractionEnabled = true
            imageView.contentMode = .scaleAspectFill
            imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(pushWebAction)))
            contentView.addSubview(imageView)
        }
    }
    
    @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)
    }
}