//
|
// AwardListView.swift
|
// DolphinEnglishLearnStudent
|
//
|
// Created by 无故事王国 on 2024/5/23.
|
//
|
|
import UIKit
|
|
class AwardListView: UIView,JQNibView{
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
@IBOutlet weak var view_container: UIView!
|
private var items = [RecommendModel]()
|
private var clickClouse:((RecommendModel)->Void)!
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
self.alpha = 0
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.register(UINib(nibName: "AwardListCCell", bundle: nil), forCellWithReuseIdentifier: "_AwardListCCell")
|
view_container.transform = .init(scaleX: 0.1, y: 0.1)
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 37, bottom: 0, right: 37)
|
layoutIfNeeded()
|
}
|
|
static func show(items:[RecommendModel],clouse:@escaping (RecommendModel)->Void){
|
|
if items.count == 0{return}
|
|
let awardListView = AwardListView.jq_loadNibView()
|
awardListView.items = items
|
awardListView.clickClouse = clouse
|
sceneDelegate?.window?.addSubview(awardListView)
|
awardListView.frame = sceneDelegate?.window?.frame ?? .zero
|
|
UIView.animate(withDuration: 0.4) {
|
awardListView.alpha = 1
|
awardListView.view_container.transform = .init(translationX: 1.0, y: 1.0)
|
awardListView.layoutIfNeeded()
|
}completion: { _ in
|
awardListView.collectionView.reloadData()
|
}
|
}
|
|
@IBAction func closeAction(_ sender: UIButton) {
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.view_container.transform = .init(scaleX: 0.1, y: 0.1)
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
}
|
|
extension AwardListView:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.view_container.transform = .init(scaleX: 0.1, y: 0.1)
|
} completion: { _ in
|
self.removeFromSuperview()
|
let item = self.items[indexPath.row]
|
self.clickClouse(item)
|
}
|
}
|
}
|
|
extension AwardListView:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let item = items[indexPath.row]
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_AwardListCCell", for: indexPath) as! AwardListCCell
|
cell.setModel(item)
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return items.count
|
}
|
}
|
|
extension AwardListView:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
let w = (JQ_ScreenW - 37 * 2 - 144 * 2 - 44 * 2) / 3.0
|
return CGSize(width: w, height: w * 1.552)
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 44
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 44
|
}
|
}
|