无故事王国
2023-06-28 a56ff03fc62bb894160f9b71fc54f66e77e48712
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
//
//  CourseOnlineListVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/15.
//
 
import UIKit
import JQTools
import MJRefresh
 
class CourseOnlineListVC: BaseVC {
 
    lazy var searchView:CourseOnlineSearchView = {
        let searchV = CourseOnlineSearchView.jq_loadNibView()
        searchV.frame = CGRect(x: 0, y: JQ_NavBarHeight, width: JQ_ScreenW, height: JQ_ScreenW * 0.564 + 57)
        searchV.alpha = 1
        return searchV
    }()
 
    var collectionView:UICollectionView!
 
    override func viewDidLoad() {
        super.viewDidLoad()
    }
 
    override func setUI() {
        let flowlayout = OnlineLayout()
 
        flowlayout.itemSize = CGSize(width: (JQ_ScreenW - 50) / 2, height: 195)
        flowlayout.minimumLineSpacing = 22
        flowlayout.minimumLineSpacing = 22
//        flowlayout.sectionHeadersPinToVisibleBounds = true
        flowlayout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 52)
        collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowlayout)
        collectionView.register(UINib(nibName: "CourseOnlineCCell", bundle: nil), forCellWithReuseIdentifier: "_CourseOnlineCCell")
        collectionView.register(UINib(nibName: "CourseOnlineHeadView", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "_CourseOnlineHeadView")
        collectionView.delegate = self
        collectionView.dataSource = self
 
        let insertH = JQ_ScreenW * 0.564 + 57
        collectionView.contentInset = UIEdgeInsets(top: insertH, left: 14, bottom: 14, right: 14)
        collectionView.scrollIndicatorInsets = UIEdgeInsets(top: insertH, left: 0, bottom: 0, right: 0)
 
        view.addSubview(collectionView)
        collectionView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
 
        view.addSubview(searchView)
 
    }
 
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let insertH = scrollView.contentOffset.y  + JQ_ScreenW * 0.5641 + 57
        searchView.jq_y = -insertH
    }
}
 
extension CourseOnlineListVC:UICollectionViewDelegate{
 
}
 
extension CourseOnlineListVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
 
        if kind == UICollectionView.elementKindSectionHeader{
            let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "_CourseOnlineHeadView", for: indexPath) as! CourseOnlineHeadView
            headerView.indexPath = indexPath
            headerView.moreClouse = { [weak self] index in
                let vc = CourseOnlineSubListVC()
                vc.title = self?.title ?? ""
                self?.push(vc: vc)
            }
            return headerView
        }
 
        return UICollectionReusableView()
    }
 
 
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CourseOnlineCCell", for: indexPath) as! CourseOnlineCCell
        return cell
    }
 
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 3
    }
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
}
 
class OnlineLayout:UICollectionViewFlowLayout{
 
}