杨锴
2024-11-06 63f7ed967433acee3ae8764c7a077e15c29c41f2
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
//  CountdownChooseListView.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/14.
//
 
import UIKit
import JQTools
import RxSwift
 
class CountdownChooseListView: UIView,JQNibView{
 
    enum CountDownStatus {
        case close
        case choose(Int)
    }
 
                @IBOutlet weak var btn_cancel: UIButton!
                @IBOutlet weak var stackView: UIStackView!
                @IBOutlet weak var view_content: UIView!
                @IBOutlet weak var cons_bottom: NSLayoutConstraint!
                @IBOutlet weak var tf_input: UITextField!
                private var disposeBag = DisposeBag()
                private var clouse:((CountDownStatus)->Void)?
    private var status:CountDownStatus = .close
 
                var numberMinutes = 1
 
                override func awakeFromNib() {
                                super.awakeFromNib()
                                tf_input.text = numberMinutes.string
                                tf_input.tintColor = UIColor(hexString: "#8AAE65")
 
                                view_content.jq_addCorners(corner: [.topLeft,.topRight], radius: 20)
                                alpha = 0
                                cons_bottom.constant = -JQ_ScreenH
                                layoutIfNeeded()
 
                                NotificationCenter.default.rx.notification(UIControl.keyboardWillShowNotification, object: nil).take(until: self.rx.deallocated).subscribe(onNext: {noti in
                                                if let obj = noti.userInfo{
                                                                let rect = obj[UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
                                                                let duration = obj[UIResponder.keyboardAnimationDurationUserInfoKey] as! CGFloat
                                                                self.layoutIfNeeded()
                                                                self.userCustomer()
                                                                UIView.animate(withDuration:duration) {
                                                                                self.cons_bottom.constant = rect.height
                                                                                self.layoutIfNeeded()
                                                                }
                                                }
                                }).disposed(by: disposeBag)
 
                                NotificationCenter.default.rx.notification(UIControl.keyboardWillHideNotification, object: nil).take(until: self.rx.deallocated).subscribe(onNext: {noti in
                                                if let obj = noti.userInfo{
                                                                let duration = obj[UIResponder.keyboardAnimationDurationUserInfoKey] as! CGFloat
                                                                self.layoutIfNeeded()
 
                                                                UIView.animate(withDuration:duration) {
                                                                                self.cons_bottom.constant = 0
                                                                                self.layoutIfNeeded()
                                                                }
                                                }
                                }).disposed(by: disposeBag)
 
                                tf_input.rx.text.orEmpty.subscribe(onNext: {[unowned self] text in
                                                self.numberMinutes = text.int ?? 1
            self.status = .choose(self.numberMinutes)
                                }).disposed(by: disposeBag)
 
                }
 
                static func show(clouse:@escaping (CountDownStatus)->Void){
                                let countdownChooseListView  = CountdownChooseListView.jq_loadNibView()
                                countdownChooseListView.clouse = clouse
                                countdownChooseListView.frame = sceneDelegate?.window?.frame ?? .zero
                                sceneDelegate?.window?.addSubview(countdownChooseListView)
 
                                countdownChooseListView.cons_bottom.constant = 0
                                UIView.animate(withDuration: 0.4) {
                                                countdownChooseListView.alpha = 1
                                                countdownChooseListView.layoutIfNeeded()
                                }
                }
 
                
                override func layoutSubviews() {
                                super.layoutSubviews()
 
                                btn_cancel.jq_gradientNibColor(colorArr: [UIColor(hexStr: "#8EA47A").cgColor,UIColor(hexStr: "#AFCA98").cgColor], cornerRadius: 18.5)
                }
 
    private func closeAni(){
        cons_bottom.constant = -JQ_ScreenH
        UIView.animate(withDuration: 0.4) {
            self.alpha = 0
            self.layoutIfNeeded()
        }
    }
 
 
                @IBAction func customReduceAction(_ sender: Any) {
                                userCustomer()
        var t = tf_input.text?.int ?? 1
                                t = max(1,t)
        status = .choose(t)
        tf_input.text = t.string
                }
 
                @IBAction func customAddAction(_ sender: Any) {
                                userCustomer()
        var t = tf_input.text?.int ?? 1
        t += 1
        status = .choose(t)
                                tf_input.text = t.string
                }
 
    @IBAction func closeAction(_ sender: UIButton) {
        closeAni()
    }
    
                @IBAction func cancelAction(_ sender: UIButton) {
                                endEditing(true)
        clouse?(status)
        closeAni()
                }
 
                private func userCustomer(){
                                for subView in stackView.arrangedSubviews as! [TapBtn]{
                                                if subView.tag == 106{
                                                                for v in subView.subviews{
                                                                                if let label = v as? UILabel{
                                                                                                label.textColor = UIColor(hexString: "#8AAE65")
                                                                                }
 
                                                                                if let image = v as? UIImageView{
                                                                                                image.image = UIImage(named: "icon_choose_small_s")
                                                                                }
                                                                }
                                                }else{
                                                                for v in subView.subviews{
                                                                                if let label = v as? UILabel{
                                                                                                label.textColor = UIColor(hexString: "#5C5C5C")
                                                                                }
 
                                                                                if let image = v as? UIImageView{
                                                                                                image.image = UIImage(named: "icon_choose_small")
                                                                                }
                                                                }
                                                }
                                }
                }
 
                
                @IBAction func clickAction(_ sender: TapBtn) {
                                endEditing(true)
 
 
                                for subView in stackView.arrangedSubviews as! [TapBtn]{
                                                if subView.tag == sender.tag{
 
                var text:String?
                for v in subView.subviews{
                    if let label = v as? UILabel{
                        label.textColor = UIColor(hexString: "#8AAE65")
                        text = label.text
                        break
                    }
                }
 
                for v in subView.subviews{
                    if let image = v as? UIImageView{
                        image.image = UIImage(named: "icon_choose_small_s")
                        break
                    }
                }
 
 
                switch text! {
                    case "关闭倒计时":
                        numberMinutes = -1
                        status = .close
                    case "自定义":
                        numberMinutes = self.tf_input.text!.int ?? 1
                        status = .choose(numberMinutes)
                    default:
                        numberMinutes = text!.jq_filterNum().int ?? 0
//                        tf_input.text = numberMinutes.string
                        status = .choose(numberMinutes)
                }
                                                }else{
                                                                for v in subView.subviews{
                                                                                if let label = v as? UILabel{
                                                                                                label.textColor = UIColor(hexString: "#5C5C5C")
                                                                                }
 
                                                                                if let image = v as? UIImageView{
                                                                                                image.image = UIImage(named: "icon_choose_small")
                                                                                }
                                                                }
                                                }
                                }
                }
}