杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
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
//
//  ChooseOptView.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/15.
//
 
import UIKit
import JQTools
 
class ChooseOptView: UIView,JQNibView{
 
                @IBOutlet weak var view_container: UIView!
                @IBOutlet weak var tableView: UITableView!
                @IBOutlet weak var cons_hight: NSLayoutConstraint!
                @IBOutlet weak var cons_bottom: NSLayoutConstraint!
                @IBOutlet weak var cons_cancel_bottom: NSLayoutConstraint!
                private var items = [String]()
                private var clouse:((Int)->Void)!
 
                override func awakeFromNib() {
                                super.awakeFromNib()
 
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.separatorStyle = .none
                                tableView.register(UITableViewCell.self, forCellReuseIdentifier: "_cell")
                                alpha = 0
                                cons_hight.constant = 0
                                cons_cancel_bottom.constant = UIDevice.jq_safeEdges.bottom
                                cons_bottom.constant = -JQ_ScreenW
                                layoutIfNeeded()
                }
 
                static func show(titles:[String],clouse:@escaping (Int)->Void){
                                let optView = ChooseOptView.jq_loadNibView()
                                optView.items = titles
                                optView.clouse = clouse
                                optView.frame = sceneDelegate?.window?.frame ?? .zero
                                sceneDelegate?.window?.addSubview(optView)
 
                                optView.cons_hight.constant = Double(titles.count) * 56
                                optView.cons_bottom.constant = -UIDevice.jq_safeEdges.bottom
                                UIView.animate(withDuration: 0.4) {
                                                optView.alpha = 1
                                                optView.layoutIfNeeded()
                                }
                }
 
                override func layoutSubviews() {
                                super.layoutSubviews()
                                view_container.jq_cornerPart(byRoundingCorners: [.topLeft,.topRight], radii: 22)
                }
 
                @IBAction func cancelAction(_ sender: Any) {
                                self.cons_bottom.constant = -JQ_ScreenW
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.layoutIfNeeded()
                                } completion: { _ in
                                                self.removeFromSuperview()
                                }
                }
}
 
extension ChooseOptView:UITableViewDelegate & UITableViewDataSource{
 
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                                clouse(indexPath.row)
                                self.cons_bottom.constant = -JQ_ScreenW
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.layoutIfNeeded()
                                } completion: { _ in
                                                self.removeFromSuperview()
                                }
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return items.count
                }
                
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_cell")
                                cell!.textLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
                                cell!.textLabel?.textColor = UIColor(hexString: "#92A87D")
                                cell!.selectionStyle = .none
                                cell?.textLabel?.textAlignment = .center
                                cell?.textLabel?.text = items[indexPath.row]
                                return cell!
                }
                
                func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                                return 56
                }
}