99 lines
4.3 KiB
Swift
99 lines
4.3 KiB
Swift
//
|
||
// MPPositive_MoreContentViewController.swift
|
||
// MusicPlayer
|
||
//
|
||
// Created by Mr.Zhou on 2024/4/28.
|
||
//
|
||
|
||
import UIKit
|
||
///更多页面(两种款式,单曲/视频一种,列表/专辑一种)
|
||
class MPPositive_MoreContentViewController: MPPositive_BaseViewController {
|
||
//约束类型设置
|
||
enum MoreShowType: Int {
|
||
case Single = 0
|
||
case List = 1
|
||
|
||
//布局Layout
|
||
var layout:UICollectionViewFlowLayout{
|
||
let layout = UICollectionViewFlowLayout()
|
||
layout.sectionInset = .init(top: 0, left: 18*width, bottom: 50*width, right: 16*width)
|
||
switch self {
|
||
case .Single:
|
||
layout.itemSize = .init(width: 339*width, height: 237*width)
|
||
layout.minimumLineSpacing = 32*width
|
||
case .List:
|
||
layout.itemSize = .init(width: 162*width, height: 210*width)
|
||
layout.minimumLineSpacing = 32*width
|
||
layout.minimumInteritemSpacing = 15*width
|
||
}
|
||
return layout
|
||
}
|
||
}
|
||
///列表展示类型
|
||
private var showType:MoreShowType = .Single{
|
||
didSet{
|
||
collectionView.collectionViewLayout = showType.layout
|
||
collectionView.reloadData()
|
||
}
|
||
}
|
||
private lazy var collectionView:UICollectionView = {
|
||
let collectionView:UICollectionView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: screen_Height), collectionViewLayout: showType.layout)
|
||
collectionView.showsVerticalScrollIndicator = false
|
||
collectionView.showsHorizontalScrollIndicator = false
|
||
collectionView.backgroundColor = .clear
|
||
collectionView.dataSource = self
|
||
collectionView.delegate = self
|
||
collectionView.register(MPPositive_MoreListContentCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_MoreListContentCollectionViewCellID)
|
||
collectionView.register(MPPositive_HomeListFifthCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_HomeListFifthCollectionViewCellID)
|
||
collectionView.contentInset = .init(top: 0, left: 0, bottom: 70*width, right: 0)
|
||
return collectionView
|
||
}()
|
||
//列表cell
|
||
private let MPPositive_MoreListContentCollectionViewCellID = "MPPositive_MoreListContentCollectionViewCell"
|
||
//单曲cell
|
||
private let MPPositive_HomeListFifthCollectionViewCellID = "MPPositive_HomeListFifthCollectionViewCell"
|
||
//传值
|
||
var browseModuleList:MPPositive_BrowseModuleListViewModel!
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
setTitle("Report")
|
||
setPopBtn()
|
||
confirgue()
|
||
}
|
||
private func confirgue() {
|
||
view.backgroundColor = .init(hex: "#121212")
|
||
view.addSubview(collectionView)
|
||
collectionView.snp.makeConstraints { make in
|
||
make.top.equalTo(navView.snp.bottom).offset(32*width)
|
||
make.left.right.bottom.equalToSuperview()
|
||
}
|
||
}
|
||
override func viewWillAppear(_ animated: Bool) {
|
||
super.viewWillAppear(animated)
|
||
reload()
|
||
}
|
||
//传递数据检测
|
||
private func reload() {
|
||
//根据传递的数据类型进行检测,判断是什么类型的
|
||
showType = .init(rawValue: browseModuleList.items.first?.browseItem.itemType.rawValue ?? 0)!
|
||
}
|
||
}
|
||
//MARK: - collectionView
|
||
extension MPPositive_MoreContentViewController: UICollectionViewDataSource, UICollectionViewDelegate {
|
||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||
return browseModuleList.items.count
|
||
}
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||
switch showType {
|
||
case .Single:
|
||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_HomeListFifthCollectionViewCellID, for: indexPath) as! MPPositive_HomeListFifthCollectionViewCell
|
||
cell.itemViewModel = browseModuleList.items[indexPath.row]
|
||
return cell
|
||
case .List:
|
||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_MoreListContentCollectionViewCellID, for: indexPath) as! MPPositive_MoreListContentCollectionViewCell
|
||
cell.itemViewModel = browseModuleList.items[indexPath.row]
|
||
return cell
|
||
}
|
||
}
|
||
}
|