younger_times
2023-07-05 c5e94788e59723d189642e8489423ea64271340b
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
//  HomeVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/8.
//
 
import UIKit
 
class HomeVC: BaseVC {
 
    @IBOutlet weak var collectionView: UICollectionView!
    
    
    private var layout:WaterFallFlowLayout!
    private var items = Array<String>()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        locationTool.startLocation { local in
            print("SUCCESS--->\(local.coordinate)")
            locationTool.stopLocation()
 
        } errorClouse: { error in
            print("ERROR--->\(error.localizedDescription)")
        }
    }
    
    
    override func setUI() {
        view.backgroundColor = UIColor(hexStr: "EEF0F3")
        
        layout = WaterFallFlowLayout()
        layout.cols = 2
        layout.sectionInset = UIEdgeInsets(top: 14, left: 34, bottom: 14, right: 34)
        layout.delegate = self
        collectionView.collectionViewLayout = layout
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = .white
        collectionView.register(UINib(nibName: "HomeCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeCCell")
        
        for index in 1...8{
            items.append("b_\(index)")
        }
        collectionView.reloadData()
    }
    
    @IBAction func joinMemberAction(_ sender: UIButton) {
        let joinMemberVC = JoinMemberIntroduceVC()
        push(vc: joinMemberVC)
    }
    
    
    @IBAction func chooseStoresAction(_ sender: TapBtn) {
        StoresChooseView.show()
    }
 
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
}
 
extension HomeVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0{
            let vc = CourseListVC()
            push(vc: vc)
        }
        
        if indexPath.row == 1{
            let vc = ActivityListVC()
            push(vc: vc)
        }
 
        if indexPath.row == 2{
            let vc = CourseOnlineListVC()
            vc.title = "看视频得奖励"
            push(vc: vc)
        }
 
        if indexPath.row == 3{
            let vc = CourseOnlineListVC()
            vc.title = "线上课得积分"
            push(vc: vc)
        }
 
        if indexPath.row == 4{
            let vc = YardListVC()
            push(vc: vc)
        }
 
        if indexPath.row == 5{
            let vc = WelfareFreeVC()
            push(vc: vc)
        }
 
        if indexPath.row == 7{
            let vc = WelfareWeeklyListVC()
            push(vc: vc)
        }
    }
    
}
 
extension HomeVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeCCell", for: indexPath) as! HomeCCell
        cell.img.image = UIImage(named: items[indexPath.row])
        return cell
    }
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return items.count
    }
    
}
 
extension HomeVC: WaterFallLayoutDelegate{
    func waterFlowLayout(_ waterFlowLayout: WaterFallFlowLayout, itemHeight indexPath: IndexPath) -> CGFloat {
        if let tempImg = UIImage(named: items[indexPath.row]){
            let radio = tempImg.size.width / tempImg.size.height
            if radio >= 0.8{
                return 185
            }else{
                return 288
            }
        }
        
        return 288
    }
}