杨锴
2024-11-07 62a24b3c7cf92919a93ee575e9460037e1a53816
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
//
//  ChooseOptTitleView.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/9/10.
//
 
import UIKit
import JQTools
 
class ChooseOptTitleView: UIView,JQNibView{
                @IBOutlet weak var label_title: UILabel!
                @IBOutlet weak var tableView: UITableView!
                @IBOutlet weak var view_container: UIView!
                @IBOutlet weak var cons_bottom: NSLayoutConstraint!
                @IBOutlet weak var cons_tableHei: NSLayoutConstraint!
 
                private var items = [String]()
                private var clouse:((String)->Void)!
                private var selectIndex:IndexPath?
 
                override func awakeFromNib() {
                                super.awakeFromNib()
                                cons_bottom.constant = -JQ_ScreenW
                                alpha = 0
                                cons_tableHei.constant = 0
                                backgroundColor = .clear
                                view_container.backgroundColor = .white.withAlphaComponent(0.9)
                                tableView.register(UINib(nibName: "ChooseOptTitleTCell", bundle: nil), forCellReuseIdentifier: "_ChooseOptTitleTCell")
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.separatorStyle = .none
                                layoutIfNeeded()
                }
 
                static func show(title:String,contents:[String],clouse:@escaping (String)->Void){
                                let titleView = ChooseOptTitleView.jq_loadNibView()
                                titleView.label_title.text = title
                                titleView.items = contents
                                titleView.clouse = clouse
                                sceneDelegate?.window?.addSubview(titleView)
                                titleView.frame = sceneDelegate?.window?.frame ?? .zero
 
                                titleView.cons_bottom.constant = 0
                                titleView.alpha = 1
                                titleView.cons_tableHei.constant = Double(contents.count) * 61
                                UIView.animate(withDuration: 0.5) {
                                                titleView.layoutIfNeeded()
                                }
                }
 
                override func layoutSubviews() {
                                super.layoutSubviews()
                                view_container.jq_cornerPartWithShadow(byRoundingCorners: [.topLeft,.topRight], radii: 20)
                }
 
                @IBAction func cancelAction(_ sender: UIButton) {
                                hidden()
                }
 
    @IBAction func completeAction(_ sender: UIButton) {
 
        guard selectIndex != nil else{
            alertError(msg: "请选择举报内容");return
        }
 
        CommonAlertView.show(title: "提示", content: "确认举报该提问?") {[weak self] state in
            guard let weakSelf = self else { return }
 
            if state{
                weakSelf.clouse(weakSelf.items[weakSelf.selectIndex!.row])
                weakSelf.hidden()
            }
        }
    }
 
                private func hidden(){
                                cons_bottom.constant = -JQ_ScreenW
                                cons_tableHei.constant = 0
                                UIView.animate(withDuration: 0.6) {
                                                self.alpha = 0
                                                self.layoutIfNeeded()
                                } completion: { _ in
                                                self.removeFromSuperview()
                                }
                }
}
 
extension ChooseOptTitleView:UITableViewDelegate{
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                                selectIndex = indexPath
                                tableView.reloadData()
                }
}
 
extension ChooseOptTitleView:UITableViewDataSource{
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_ChooseOptTitleTCell") as! ChooseOptTitleTCell
                                cell.label_title.text = items[indexPath.row]
 
                                if indexPath == selectIndex{
                                                cell.label_title.textColor = UIColor(hexString: "#8AAE65")
                                                cell.img_choose.image = UIImage(named: "icon_choose_small_s")
                                }else{
                                                cell.label_title.textColor = UIColor(hexString: "#5C5C5C")
                                                cell.img_choose.image = UIImage(named: "icon_choose_small")
                                }
                                return cell
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return items.count
                }
 
                func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                                return 61
                }
}