Visual_Novel_iOS/crush/Crush/Src/Components/UI/Dialog/UnlockPriceSetDialogControl...

105 lines
3.3 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UnlockPriceSetDialogController.swift
// Crush
//
// Created by Leon on 2025/7/23.
//
import UIKit
///
class UnlockPriceSetDialogController: BaseMaskPopDialogController {
var titleLabel: UILabel!
var textFiled: CLTextField!
var button: StyleButton!
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
setupDats()
setupEvents()
}
private func setupViews() {
titleLabel = {
let v = UILabel()
v.textColor = .c.ctpn
v.font = .t.ttm
v.numberOfLines = 0
block.addSubview(v)
v.textAlignment = .center
v.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(24)
make.trailing.equalToSuperview().offset(-24)
make.top.equalToSuperview().offset(32)
}
return v
}()
textFiled = {
let v = CLTextField()
block.addSubview(v)
v.keyboardType = .decimalPad
v.placeholder = "Price"
v.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(24)
make.trailing.equalToSuperview().offset(-24);
make.top.equalTo(titleLabel.snp.bottom).offset(24)
}
v.setupLeftCoinIconView()
return v
}()
button = {
let v = StyleButton()
v.primary(size: .large)
block.addSubview(v)
v.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(24)
make.trailing.equalToSuperview().offset(-24);
make.top.equalTo(textFiled.snp.bottom).offset(28)
make.bottom.equalToSuperview().offset(-16)
}
return v
}()
titleLabel.text = "Unlock Method"
button.setTitle("Confirm", for: .normal)
}
private func setupDats() {
}
private func setupEvents() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChanged(noti:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
@objc func keyboardWillChanged(noti: Notification) {
guard let userInfo = noti.userInfo else { return }
let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! TimeInterval
let endFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
//let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey]! as! Int
//let beginFrame = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
if endFrame.origin.y >= UIScreen.main.bounds.height {
UIView.animate(withDuration: duration) {[weak self] in
self?.block.snp.updateConstraints { make in
make.centerY.equalToSuperview()
}
self?.view.layoutIfNeeded()
}
}else{
UIView.animate(withDuration: duration) {[weak self] in
self?.block.snp.updateConstraints { make in
make.centerY.equalToSuperview().offset(-endFrame.height * 0.5)
}
self?.view.layoutIfNeeded()
}
}
}
}