//
|
// 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")
|
}
|
}
|
}
|
}
|
}
|
}
|