123 lines
3.6 KiB
Swift
123 lines
3.6 KiB
Swift
//
|
|
// FS_CollectVC.swift
|
|
// Funny_sounds
|
|
//
|
|
// Created by 忆海16 on 2024/8/14.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
class FS_CollectVC: RootVC {
|
|
var collectArr = [AudioFile]()
|
|
|
|
lazy var collectionView: UICollectionView = {
|
|
let layout = UICollectionViewFlowLayout()
|
|
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
|
collectionView.backgroundColor = .clear
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
return collectionView
|
|
}()
|
|
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
setUI()
|
|
setcollectionView()
|
|
}
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
|
|
self.navigationController?.navigationBar.isHidden = true
|
|
collectArr = collectManager.shared.getAllFavorites()
|
|
|
|
collectionView.reloadData()
|
|
}
|
|
|
|
// MARK: - 收藏UI
|
|
|
|
func setUI(){
|
|
|
|
lazy var bgImageV:UIImageView = {
|
|
let bgImageV = UIImageView()
|
|
bgImageV.image = UIImage(named: "collectBg")
|
|
bgImageV.contentMode = .scaleAspectFill
|
|
|
|
return bgImageV
|
|
}()
|
|
|
|
lazy var titleImageV:UIImageView = {
|
|
let titleImageV = UIImageView()
|
|
titleImageV.image = UIImage(named: "tittleimage")
|
|
return titleImageV
|
|
}()
|
|
|
|
|
|
collectionView.backgroundColor = .clear
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
|
|
self.view.addSubview(bgImageV)
|
|
self.view.addSubview(titleImageV)
|
|
self.view.addSubview(collectionView)
|
|
|
|
bgImageV.snp.makeConstraints { make in
|
|
make.width.equalTo(self.view)
|
|
make.height.equalTo(self.view)
|
|
}
|
|
|
|
titleImageV.snp.makeConstraints { make in
|
|
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(15)
|
|
make.height.equalTo(81)
|
|
make.width.equalTo(self.view)
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.top.equalTo(titleImageV.snp.bottom).offset(25)
|
|
make.width.equalToSuperview()
|
|
make.bottom.equalTo(self.view.safeAreaLayoutGuide)
|
|
}
|
|
|
|
|
|
}
|
|
// MARK: -设置collectionView
|
|
func setcollectionView(){
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
let layout = collectCollectionViewFlowLayout()
|
|
collectionView.collectionViewLayout = layout
|
|
layout.scrollDirection = .vertical
|
|
|
|
collectionView.register(FS_CollectCollectionCell.self, forCellWithReuseIdentifier: "FS_CollectCollectionCell")
|
|
|
|
}
|
|
|
|
|
|
}
|
|
// MARK: -设置collectionView代理
|
|
extension FS_CollectVC:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return collectArr.count
|
|
return 10
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FS_CollectCollectionCell", for: indexPath)as!FS_CollectCollectionCell
|
|
cell.model = collectArr[indexPath.row]
|
|
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
|
|
|
|
let vc = FS_DetailsVC()
|
|
vc.model = self.collectArr[indexPath.row]
|
|
navigationController?.pushViewController(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
|
}
|