PswPayView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // PswPayView.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/9.
  6. //
  7. import UIKit
  8. class PswPayView: UIView {
  9. @IBOutlet weak var blackView: UIView!
  10. @IBOutlet weak var priceLab: UILabel!
  11. @IBOutlet weak var pswT1: UITextField!
  12. @IBOutlet weak var pswT2: UITextField!
  13. @IBOutlet weak var pswT3: UITextField!
  14. @IBOutlet weak var pswT4: UITextField!
  15. @IBOutlet weak var pswT5: UITextField!
  16. @IBOutlet weak var pswT6: UITextField!
  17. var pswPayBlock : ((String?)->Void)?
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. // Initialization code
  21. pswT1.delegate = self
  22. pswT2.delegate = self
  23. pswT3.delegate = self
  24. pswT4.delegate = self
  25. pswT5.delegate = self
  26. pswT6.delegate = self
  27. pswT1.becomeFirstResponder()
  28. }
  29. @IBAction func BackAction(_ sender: UIButton) {
  30. self.hidden()
  31. }
  32. public func show(){
  33. self.pswT1.text = ""
  34. self.pswT2.text = ""
  35. self.pswT3.text = ""
  36. self.pswT4.text = ""
  37. self.pswT5.text = ""
  38. self.pswT6.text = ""
  39. pswT1.becomeFirstResponder()
  40. kAppDelegateWindow.addSubview(self)
  41. self.blackView.alpha = 0
  42. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  43. UIView.animate(withDuration: 0.5) {
  44. self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  45. self.layoutIfNeeded()
  46. }
  47. DELAY(0.5) {
  48. self.blackView.alpha = 0.3
  49. }
  50. }
  51. /// 隐藏
  52. public func hidden(){
  53. self.blackView.alpha = 0
  54. UIView.animate(withDuration: 0.5) {
  55. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  56. self.layoutIfNeeded()
  57. }
  58. DELAY(0.5) {
  59. self.removeFromSuperview()
  60. }
  61. }
  62. func isPstWorkOK(){
  63. if (pswT1.text?.count ?? 0) == 1 && (pswT2.text?.count ?? 0) == 1 && (pswT3.text?.count ?? 0) == 1 && (pswT4.text?.count ?? 0) == 1 && (pswT5.text?.count ?? 0) == 1 && (pswT6.text?.count ?? 0) == 1{
  64. if self.pswPayBlock != nil{
  65. self.pswPayBlock!("\(pswT1.text ?? "")\(pswT2.text ?? "")\(pswT3.text ?? "")\(pswT4.text ?? "")\(pswT5.text ?? "")\(pswT6.text ?? "")")
  66. }
  67. self.hidden()
  68. }
  69. }
  70. }
  71. extension PswPayView : UITextFieldDelegate{
  72. func textFieldDidEndEditing(_ textField: UITextField) {
  73. textField.layer.borderColor = UIColor.clear.cgColor
  74. }
  75. func textFieldDidBeginEditing(_ textField: UITextField) {
  76. textField.layer.borderColor = kThemeColor.cgColor
  77. }
  78. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  79. if string == "\n" || string == ""{
  80. return true
  81. }
  82. if string.count == 0{
  83. return true
  84. }
  85. if string.count == 1{
  86. if textField.text?.count == 0{
  87. textField.text = string
  88. }
  89. if textField == pswT1{
  90. self.isPstWorkOK()
  91. pswT2.becomeFirstResponder()
  92. }
  93. if textField == pswT2{
  94. self.isPstWorkOK()
  95. pswT3.becomeFirstResponder()
  96. }
  97. if textField == pswT3{
  98. self.isPstWorkOK()
  99. pswT4.becomeFirstResponder()
  100. }
  101. if textField == pswT4{
  102. self.isPstWorkOK()
  103. pswT5.becomeFirstResponder()
  104. }
  105. if textField == pswT5{
  106. self.isPstWorkOK()
  107. pswT6.becomeFirstResponder()
  108. }
  109. if textField == pswT6{
  110. self.isPstWorkOK()
  111. }
  112. return false
  113. }
  114. return false
  115. }
  116. }