103 lines
3.2 KiB
Swift
103 lines
3.2 KiB
Swift
//
|
|
// VPHomeBannerContentCell.swift
|
|
// Veloria
|
|
//
|
|
// Created by Veloria on 2025/5/20.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class VPHomeBannerContentCell: VPHomeItemContentCell {
|
|
|
|
override class var moduleKey: VPHomeModuleItem.ModuleKey {
|
|
return .banner
|
|
}
|
|
|
|
override var item: VPHomeModuleItem? {
|
|
didSet {
|
|
pageControl.count = item?.list?.count ?? 0
|
|
bannerView.reloadData()
|
|
}
|
|
}
|
|
|
|
private lazy var bannerView: ZKCycleScrollView = {
|
|
let view = ZKCycleScrollView(frame: .zero, shouldInfiniteLoop: true)
|
|
view.delegate = self
|
|
view.dataSource = self
|
|
view.hidesPageControl = true
|
|
view.layer.cornerRadius = 10
|
|
view.layer.masksToBounds = true
|
|
view.loadCompletion = { [weak self] in
|
|
guard let self = self else { return }
|
|
self.pageControl.currentIndex = self.bannerView.currentIdx
|
|
}
|
|
view.register(VPHomeBannerCell.self, forCellWithReuseIdentifier: "cell")
|
|
return view
|
|
}()
|
|
|
|
private lazy var pageControl: VPHomePageControlView = {
|
|
let view = VPHomePageControlView()
|
|
return view
|
|
}()
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
vp_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension VPHomeBannerContentCell {
|
|
|
|
private func vp_setupUI() {
|
|
containerView.addSubview(bannerView)
|
|
bannerView.addSubview(pageControl)
|
|
|
|
bannerView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(15)
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview()
|
|
make.bottom.equalToSuperview()
|
|
make.height.equalTo(182)
|
|
}
|
|
|
|
pageControl.snp.makeConstraints { make in
|
|
make.bottom.equalToSuperview().offset(-10)
|
|
make.right.equalToSuperview().offset(-10)
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- ZKCycleScrollViewDataSource ZKCycleScrollViewDelegate --------------
|
|
extension VPHomeBannerContentCell: ZKCycleScrollViewDataSource, ZKCycleScrollViewDelegate {
|
|
|
|
func numberOfItems(in cycleScrollView: ZKCycleScrollView) -> Int {
|
|
return self.item?.list?.count ?? 0
|
|
}
|
|
|
|
func cycleScrollView(_ cycleScrollView: ZKCycleScrollView, cellForItemAt index: Int) -> ZKCycleScrollViewCell {
|
|
let cell = cycleScrollView.dequeueReusableCell(withReuseIdentifier: "cell", for: index) as! VPHomeBannerCell
|
|
cell.model = self.item?.list?[index]
|
|
return cell
|
|
}
|
|
|
|
func cycleScrollView(_ cycleScrollView: ZKCycleScrollView, didScrollFromIndex fromIndex: Int, toIndex: Int) {
|
|
pageControl.currentIndex = toIndex
|
|
}
|
|
|
|
func cycleScrollView(_ cycleScrollView: ZKCycleScrollView, didSelectItemAt index: Int) {
|
|
guard let model = self.item?.list?[index] else { return }
|
|
|
|
let vc = VPDetailPlayerViewController()
|
|
vc.shortPlayId = model.short_play_id
|
|
self.viewController?.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
}
|