younger_times
2023-06-09 66e92e00d206dc19a4066b6f3f58f30e5c532646
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
//
//  CourseSubTypeView.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/9.
//
 
import UIKit
import JQTools
 
class CourseSubTypeView: UIView,JQNibView{
 
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var cons_tableHeight: NSLayoutConstraint!
    private var closeClouse:(()->Void)?
    private var clouse:((String)->Void)?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UINib(nibName: "Common_1_TCell", bundle: nil), forCellReuseIdentifier: "_Common_1_TCell")
        alpha = 0
        cons_tableHeight.constant = 0
        layoutIfNeeded()
    }
    
    static func show(inView:UIView,afterView:UIView,items:[String],clouse:@escaping (String)->Void,closeClouse:@escaping ()->Void){
        let subTypeView = CourseSubTypeView.jq_loadNibView()
        subTypeView.closeClouse = closeClouse
        subTypeView.clouse = clouse
        inView.addSubview(subTypeView)
        subTypeView.snp.makeConstraints { make in
            make.top.equalTo(afterView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        UIView.animate(withDuration: 0.2) {
            subTypeView.alpha = 1
        } completion: { _ in
            subTypeView.cons_tableHeight.constant = 220
            UIView.animate(withDuration: 0.2) {
                subTypeView.layoutIfNeeded()
            }
        }
    }
    
    @IBAction func closeAction(_ sender: UIButton) {
        cons_tableHeight.constant = 0
        UIView.animate(withDuration: 0.2) {
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.closeClouse?()
        }
    }
}
 
extension CourseSubTypeView:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        cons_tableHeight.constant = 0
        UIView.animate(withDuration: 0.2) {
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.clouse?("")
            self.closeClouse?()
        }
    }
}
 
extension CourseSubTypeView:UITableViewDataSource{
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "_Common_1_TCell") as! Common_1_TCell
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    
}