154 lines
4.4 KiB
Swift
154 lines
4.4 KiB
Swift
//
|
|
// SPEpisodeView.swift
|
|
// ShortPlay
|
|
//
|
|
// Created by 曾觉新 on 2025/4/16.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPEpisodeView: HWPanModalContentView {
|
|
|
|
var currentIndex: Int = 0 {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
var shortModel: SPShortModel? {
|
|
didSet {
|
|
coverImageView.sp_setImage(url: shortModel?.image_url)
|
|
}
|
|
}
|
|
|
|
var dataArr: [SPVideoInfoModel] = [] {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
var didSelectedIndex: ((_ index: Int) -> Void)?
|
|
|
|
//MARK: UI属性
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let itemWidth = floor((kSPScreenWidth - 10 * 4 - 30) / 5)
|
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.itemSize = .init(width: itemWidth, height: 50)
|
|
layout.minimumLineSpacing = 10
|
|
layout.minimumInteritemSpacing = 10
|
|
layout.sectionInset = .init(top: 0, left: 15, bottom: 0, right: 15)
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SPCollectionView = {
|
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
SPEpisodeCell.registerCell(collectionView: collectionView)
|
|
return collectionView
|
|
}()
|
|
|
|
private lazy var indicatorView: UIView = {
|
|
let view = UIView()
|
|
view.backgroundColor = .colorFFFFFF()
|
|
view.layer.cornerRadius = 2
|
|
view.layer.masksToBounds = true
|
|
return view
|
|
}()
|
|
|
|
private lazy var coverImageView: SPImageView = {
|
|
let imageView = SPImageView()
|
|
imageView.layer.cornerRadius = 6
|
|
imageView.layer.masksToBounds = true
|
|
return imageView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
|
|
//MARK: HWPanModalPresentable
|
|
override func panScrollable() -> UIScrollView? {
|
|
return collectionView
|
|
}
|
|
|
|
override func longFormHeight() -> PanModalHeight {
|
|
return PanModalHeightMake(.content, kSPScreenHeight * (2 / 3))
|
|
}
|
|
|
|
override func showDragIndicator() -> Bool {
|
|
return false
|
|
}
|
|
|
|
override func backgroundConfig() -> HWBackgroundConfig {
|
|
let config = HWBackgroundConfig()
|
|
config.backgroundAlpha = 0.4
|
|
return config
|
|
}
|
|
|
|
override func present(in view: UIView?) {
|
|
super.present(in: view)
|
|
self.hw_contentView.addEffectView(style: .dark)
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
extension SPEpisodeView {
|
|
|
|
private func _setupUI() {
|
|
addSubview(indicatorView)
|
|
addSubview(coverImageView)
|
|
addSubview(self.collectionView)
|
|
|
|
self.indicatorView.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview().offset(15)
|
|
make.width.equalTo(30)
|
|
make.height.equalTo(4)
|
|
}
|
|
|
|
self.coverImageView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(15)
|
|
make.top.equalToSuperview().offset(39)
|
|
make.width.equalTo(55)
|
|
make.height.equalTo(74)
|
|
}
|
|
|
|
self.collectionView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPEpisodeView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPEpisodeCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
cell.videoInfoModel = self.dataArr[indexPath.row]
|
|
cell.sp_isSelected = indexPath.row == currentIndex
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return self.dataArr.count
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
guard indexPath.row != currentIndex else { return }
|
|
self.didSelectedIndex?(indexPath.row)
|
|
self.dismiss(animated: true) {
|
|
|
|
}
|
|
}
|
|
}
|