add
无故事王国
2024-06-03 3d8ce4866799bea7e66699acdeb86b60b0ba033c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
//  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
                }
}