杨锴
2024-08-14 909e20941e45f8712c012db602034b47da0bfdb0
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
//
//  CountdownChooseListView.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/14.
//
 
import UIKit
import JQTools
import RxSwift
 
class CountdownChooseListView: UIView,JQNibView{
 
                @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()
                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()
                                                                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
                                }).disposed(by: disposeBag)
 
                }
 
                static func show(){
                                let countdownChooseListView  = CountdownChooseListView.jq_loadNibView()
                                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)
                }
 
 
                @IBAction func customReduceAction(_ sender: Any) {
                                userCustomer()
                                numberMinutes-=1
 
                                numberMinutes = max(1,numberMinutes)
                                tf_input.text = numberMinutes.string
                }
 
                @IBAction func customAddAction(_ sender: Any) {
                                userCustomer()
                                numberMinutes+=1
                                tf_input.text = numberMinutes.string
                }
 
                @IBAction func cancelAction(_ sender: UIButton) {
                                endEditing(true)
                                cons_bottom.constant = -JQ_ScreenH
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.layoutIfNeeded()
                                }
                }
 
                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{
                                                                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")
                                                                                }
                                                                }
                                                }
                                }
                }
}