QSLTrialTipsAlertView.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // QSLTrialTipsAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/10/31.
  6. //
  7. import UIKit
  8. class QSLTrialTipsAlertView: UIView {
  9. lazy var contentView: UIView = {
  10. let contentViewW = 318.rpx
  11. let contentViewH = 436.rpx
  12. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: contentViewW, height: contentViewH))
  13. return contentView
  14. }()
  15. lazy var centerImage : UIImageView = {
  16. let centerImage = UIImageView()
  17. centerImage.contentMode = .scaleAspectFit
  18. centerImage.image = UIImage(named: "vip_trial_tips")
  19. return centerImage
  20. }()
  21. lazy var contentLabel: UILabel = {
  22. let label = UILabel()
  23. label.text("您已好友守护了Ta 次,\n并且有 条重要轨迹即将消失。")
  24. label.font(12)
  25. label.numberOfLines = 2
  26. label.textColor = .hexStringColor(hexString: "#B6795B")
  27. return label
  28. }()
  29. lazy var oneButton: UIButton = {
  30. let btn = UIButton()
  31. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  32. return btn
  33. }()
  34. lazy var hideButton: UIButton = {
  35. let btn = UIButton()
  36. btn.image(UIImage(named: "vip_pay_failure_close"))
  37. btn.addTarget(self, action: #selector(removeView), for: .touchUpInside)
  38. return btn
  39. }()
  40. var oneBtnClosure: (() -> ())?
  41. var hideBtnClosure: (() -> ())?
  42. class func alert(view: UIView,
  43. clickBtnClosure: @escaping () -> () = {},
  44. hideBtnClosure: @escaping () -> () = {}) {
  45. let window = QSLTrialTipsAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  46. view.addSubview(window)
  47. window.oneBtnClosure = clickBtnClosure
  48. window.hideBtnClosure = hideBtnClosure
  49. QSEventHandle.eventPush(eventName: QSLGravityConst.trial_exposure_end_popup)
  50. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  51. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  52. window.contentView.isHidden = false
  53. }
  54. }
  55. override init(frame: CGRect) {
  56. super.init(frame: frame)
  57. initView()
  58. let attr = NSMutableAttributedString()
  59. let firstAttr = NSMutableAttributedString(string: "您已好友守护了Ta")
  60. firstAttr.yy_font = UIFont.textM(12)
  61. firstAttr.yy_color = UIColor.hexStringColor(hexString: "#B6795B")
  62. attr.append(firstAttr)
  63. let randomAddCount1 = Int.random(in: 1...10)
  64. let randomAddCount2 = Int.random(in: 1...5)
  65. let firstText = "\(randomAddCount1)"
  66. let firstAttr1 = NSMutableAttributedString(string: firstText)
  67. firstAttr1.yy_font = UIFont.textM(15)
  68. firstAttr1.yy_color = .hexStringColor(hexString: "#69280E")
  69. attr.append(firstAttr1)
  70. let secondAttr = NSMutableAttributedString(string: "次,\n并且有")
  71. secondAttr.yy_font = UIFont.textB(12)
  72. secondAttr.yy_color = UIColor.hexStringColor(hexString: "#B6795B")
  73. attr.append(secondAttr)
  74. let secondText = "\(randomAddCount2)"
  75. let secondAttr1 = NSMutableAttributedString(string: secondText)
  76. secondAttr1.yy_font = UIFont.textM(15)
  77. secondAttr1.yy_color = .hexStringColor(hexString: "#69280E")
  78. attr.append(secondAttr1)
  79. let thirdAttr = NSMutableAttributedString(string: "条重要轨迹即将消失。")
  80. thirdAttr.yy_font = UIFont.textM(12)
  81. thirdAttr.yy_color = UIColor.hexStringColor(hexString: "#B6795B")
  82. attr.append(thirdAttr)
  83. contentLabel.attributedText = attr
  84. }
  85. required init?(coder: NSCoder) {
  86. fatalError("init(coder:) has not been implemented")
  87. }
  88. // 单按钮点击事件
  89. @objc func oneBtnAction() {
  90. if let oneBtnClosure = self.oneBtnClosure {
  91. oneBtnClosure()
  92. }
  93. removeView1()
  94. QSEventHandle.eventPush(eventName: QSLGravityConst.trial_click_end_popup)
  95. }
  96. @objc func removeView1() {
  97. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  98. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  99. self?.contentView.isHidden = true
  100. self?.centerImage.isHidden = true
  101. } completion: { [weak self] finished in
  102. self?.removeFromSuperview()
  103. }
  104. }
  105. // 移除
  106. @objc func removeView() {
  107. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  108. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  109. self?.contentView.isHidden = true
  110. self?.centerImage.isHidden = true
  111. } completion: { [weak self] finished in
  112. self?.hideBtnClosure?()
  113. self?.removeFromSuperview()
  114. }
  115. }
  116. }
  117. extension QSLTrialTipsAlertView {
  118. func initView() {
  119. addSubview(contentView)
  120. contentView.snp.makeConstraints { make in
  121. make.size.equalTo(CGSize(width: 318.rpx, height: 436.rpx))
  122. make.center.equalToSuperview()
  123. }
  124. contentView.addSubview(centerImage)
  125. centerImage.snp.makeConstraints { make in
  126. make.top.bottom.left.right.equalTo(0)
  127. }
  128. contentView.addSubview(contentLabel)
  129. contentLabel.snp.makeConstraints { make in
  130. make.left.equalTo(15.rpx)
  131. make.right.equalTo(-15.rpx)
  132. make.top.equalTo(68.rpx)
  133. make.height.equalTo(40.rpx)
  134. }
  135. addSubview(hideButton)
  136. hideButton.snp.makeConstraints { make in
  137. make.size.equalTo(CGSize(width: 28.rpx, height: 28.rpx))
  138. make.right.equalTo(-24.rpx)
  139. make.top.equalTo(contentView.snp.top).offset(-30.rpx)
  140. }
  141. contentView.addSubview(oneButton)
  142. oneButton.snp.makeConstraints { make in
  143. make.size.equalTo(CGSize(width: 220.rpx, height: 44.rpx))
  144. make.centerX.equalToSuperview()
  145. make.bottom.equalTo(-20.rpx)
  146. }
  147. }
  148. }