QSLRetainPopUpAlertView.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // QSLRetainPopUpAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/8/1.
  6. //
  7. import UIKit
  8. class QSLRetainPopUpAlertView: UIView {
  9. lazy var contentView: UIView = {
  10. let contentViewW = QSLConst.qsl_kScreenW - 60.rpx
  11. let contentViewH = 152.0.rpx
  12. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: contentViewW, height: contentViewH))
  13. contentView.backgroundColor = .clear
  14. return contentView
  15. }()
  16. lazy var closeButton: UIButton = {
  17. let btn = UIButton()
  18. btn.setBackgroundImage(UIImage(named: "vip_pay_failure_close"), for: .normal)
  19. btn.addTarget(self, action: #selector(closeBtnAction), for: .touchUpInside)
  20. return btn
  21. }()
  22. lazy var popBgImageView : UIImageView = {
  23. let popBgImageView = UIImageView()
  24. popBgImageView.contentMode = .scaleAspectFit
  25. popBgImageView.image = UIImage(named: "vip_pay_failure_back_ground")
  26. return popBgImageView
  27. }()
  28. ///中间描述区域
  29. lazy var middleView : UIView = {
  30. let middleView = UIView()
  31. middleView.backgroundColor = .clear
  32. return middleView
  33. }()
  34. lazy var oneButton: UIButton = {
  35. let btn = UIButton()
  36. btn.addRadius(radius: 20.rpx)
  37. btn.title("去登录")
  38. btn.textColor(.white)
  39. btn.mediumFont(14)
  40. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#7F5737"), color2: .hexStringColor(hexString: "#562B0E"), width: 200.rpx, height: 40.rpx, direction: .horizontal)
  41. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  42. return btn
  43. }()
  44. lazy var firstButton: UIButton = {
  45. let btn = UIButton()
  46. btn.isHidden = true
  47. btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
  48. btn.addRadius(radius: 20.rpx)
  49. btn.title("取消")
  50. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  51. btn.mediumFont(16)
  52. btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
  53. return btn
  54. }()
  55. lazy var secondButton: UIButton = {
  56. let btn = UIButton()
  57. btn.isHidden = true
  58. btn.addRadius(radius: 20.rpx)
  59. btn.title("确认")
  60. btn.textColor(.white)
  61. btn.mediumFont(16)
  62. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
  63. btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
  64. return btn
  65. }()
  66. var oneBtnClosure: (() -> ())?
  67. var firstBtnClosure: (() -> ())?
  68. var secondBtnClosure: (() -> ())?
  69. var closeBtnClosure: (() -> ())?
  70. class func alert(view: UIView,
  71. isOneBtn: Bool = false,
  72. oneBtnText: String = "去登录",
  73. oneBtnClosure: @escaping () -> () = {},
  74. firstBtnClosure: @escaping () -> () = {},
  75. secondBtnClosure: @escaping () -> () = {},
  76. closeBtnClosure: @escaping () -> () = {}) {
  77. let window = QSLRetainPopUpAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  78. window.oneButton.title(oneBtnText)
  79. window.oneButton.isHidden = !isOneBtn
  80. window.firstButton.isHidden = isOneBtn
  81. window.secondButton.isHidden = isOneBtn
  82. window.oneBtnClosure = oneBtnClosure
  83. window.firstBtnClosure = firstBtnClosure
  84. window.secondBtnClosure = secondBtnClosure
  85. window.closeBtnClosure = closeBtnClosure
  86. window.contentView.snp.remakeConstraints { make in
  87. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 310.rpx))
  88. make.center.equalToSuperview()
  89. }
  90. view.addSubview(window)
  91. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  92. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  93. window.contentView.isHidden = false
  94. }
  95. }
  96. override init(frame: CGRect) {
  97. super.init(frame: frame)
  98. initView()
  99. }
  100. required init?(coder: NSCoder) {
  101. fatalError("init(coder:) has not been implemented")
  102. }
  103. // 单按钮点击事件
  104. @objc func oneBtnAction() {
  105. if let oneBtnClosure = self.oneBtnClosure {
  106. oneBtnClosure()
  107. }
  108. removeView()
  109. }
  110. // 取消按钮点击事件
  111. @objc func firstBtnAction() {
  112. if let firstBtnClosure = self.firstBtnClosure {
  113. firstBtnClosure()
  114. }
  115. removeView()
  116. }
  117. // 确认按钮点击事件
  118. @objc func secondBtnAction() {
  119. if let secondBtnClosure = self.secondBtnClosure {
  120. secondBtnClosure()
  121. }
  122. removeView()
  123. }
  124. // 关闭按钮点击事件
  125. @objc func closeBtnAction() {
  126. if let closeBtnClosure = self.closeBtnClosure {
  127. closeBtnClosure()
  128. }
  129. removeView()
  130. }
  131. // 移除
  132. @objc func removeView() {
  133. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  134. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  135. self?.contentView.isHidden = true
  136. self?.closeButton.isHidden = true
  137. } completion: { [weak self] finished in
  138. self?.removeFromSuperview()
  139. }
  140. }
  141. }
  142. extension QSLRetainPopUpAlertView {
  143. func initView() {
  144. addSubview(contentView)
  145. contentView.snp.makeConstraints { make in
  146. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
  147. make.center.equalToSuperview()
  148. }
  149. addSubview(closeButton)
  150. closeButton.snp.makeConstraints { make in
  151. make.bottom.equalTo(contentView.snp.top).offset(30.hpx)
  152. make.right.equalTo(contentView.snp.right).offset(-10.rpx)
  153. make.size.equalTo(CGSizeMake(24.rpx, 24.rpx))
  154. }
  155. contentView.addSubview(popBgImageView)
  156. popBgImageView.snp.makeConstraints { make in
  157. make.edges.equalToSuperview()
  158. }
  159. contentView.addSubview(oneButton)
  160. oneButton.snp.makeConstraints { make in
  161. //make.top.equalTo(contentLabel.snp.bottom).offset(24.5.rpx)
  162. make.size.equalTo(CGSize(width: 150.rpx, height: 40.rpx))
  163. make.centerX.equalToSuperview()
  164. make.bottom.equalTo(-38.rpx)
  165. }
  166. contentView.addSubview(firstButton)
  167. firstButton.snp.makeConstraints { make in
  168. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  169. make.left.equalTo(24.rpx)
  170. make.bottom.equalTo(-24.rpx)
  171. }
  172. contentView.addSubview(secondButton)
  173. secondButton.snp.makeConstraints { make in
  174. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  175. make.right.equalTo(-24.rpx)
  176. make.bottom.equalTo(-24.rpx)
  177. }
  178. }
  179. }