QSLHomeAddFriendAlertView.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // QSLHomeAddFriendView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/9/23.
  6. //
  7. import UIKit
  8. class QSLHomeAddFriendView: UIView {
  9. lazy var contentView: UIView = {
  10. let contentViewW = QSLConst.qsl_kScreenW
  11. let contentViewH = 365.0.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: "home_friends_alert_bg")
  19. return centerImage
  20. }()
  21. lazy var titleLabel: UILabel = {
  22. let label = UILabel()
  23. label.text("查找好友定位")
  24. label.boldFont(30)
  25. label.textColor = QSLColor.textColor_333
  26. return label
  27. }()
  28. lazy var contentLabel: UILabel = {
  29. let label = UILabel()
  30. label.text("去添加Ta的好友开启守护!")
  31. label.font(12)
  32. label.textColor = .hexStringColor(hexString: "#61877F")
  33. return label
  34. }()
  35. lazy var oneButton: UIButton = {
  36. let btn = UIButton()
  37. btn.addRadius(radius: 22.rpx)
  38. btn.title(QSLConfig.addFriendTitle)
  39. btn.textColor(.white)
  40. btn.mediumFont(16)
  41. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 250.rpx, height: 44.rpx, direction: .horizontal)
  42. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  43. return btn
  44. }()
  45. lazy var hideButton: UIButton = {
  46. let btn = UIButton()
  47. btn.title("下次再说")
  48. btn.textColor(.init(white: 0, alpha: 0.4))
  49. btn.font(11)
  50. btn.addTarget(self, action: #selector(removeView), for: .touchUpInside)
  51. return btn
  52. }()
  53. var oneBtnClosure: (() -> ())?
  54. var hideBtnClosure: (() -> ())?
  55. class func alert(view: UIView,
  56. clickBtnClosure: @escaping () -> () = {},
  57. hideBtnClosure: @escaping () -> () = {}) {
  58. let window = QSLHomeAddFriendView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  59. view.addSubview(window)
  60. window.oneBtnClosure = clickBtnClosure
  61. window.hideBtnClosure = hideBtnClosure
  62. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  63. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  64. window.contentView.isHidden = false
  65. }
  66. }
  67. override init(frame: CGRect) {
  68. super.init(frame: frame)
  69. initView()
  70. }
  71. required init?(coder: NSCoder) {
  72. fatalError("init(coder:) has not been implemented")
  73. }
  74. // 单按钮点击事件
  75. @objc func oneBtnAction() {
  76. if let oneBtnClosure = self.oneBtnClosure {
  77. oneBtnClosure()
  78. }
  79. removeView1()
  80. }
  81. @objc func removeView1() {
  82. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  83. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  84. self?.contentView.isHidden = true
  85. self?.centerImage.isHidden = true
  86. } completion: { [weak self] finished in
  87. self?.removeFromSuperview()
  88. }
  89. }
  90. // 移除
  91. @objc func removeView() {
  92. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  93. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  94. self?.contentView.isHidden = true
  95. self?.centerImage.isHidden = true
  96. } completion: { [weak self] finished in
  97. self?.hideBtnClosure?()
  98. self?.removeFromSuperview()
  99. }
  100. }
  101. }
  102. extension QSLHomeAddFriendView {
  103. func initView() {
  104. addSubview(contentView)
  105. contentView.snp.makeConstraints { make in
  106. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW, height: 365.0.rpx))
  107. make.center.equalToSuperview()
  108. }
  109. contentView.addSubview(centerImage)
  110. centerImage.snp.makeConstraints { make in
  111. make.top.bottom.left.right.equalTo(0)
  112. }
  113. contentView.addSubview(titleLabel)
  114. titleLabel.snp.makeConstraints { make in
  115. make.left.equalTo(54.rpx)
  116. make.right.equalTo(-54.rpx)
  117. make.top.equalTo(22.rpx)
  118. make.height.equalTo(42.rpx)
  119. }
  120. contentView.addSubview(contentLabel)
  121. contentLabel.snp.makeConstraints { make in
  122. make.left.equalTo(54.rpx)
  123. make.right.equalTo(-54.rpx)
  124. make.top.equalTo(titleLabel.snp.bottom)
  125. make.height.equalTo(14.rpx)
  126. }
  127. contentView.addSubview(hideButton)
  128. hideButton.snp.makeConstraints { make in
  129. make.size.equalTo(CGSize(width: 60.rpx, height: 28.rpx))
  130. make.centerX.equalToSuperview()
  131. make.bottom.equalTo(-18.rpx)
  132. }
  133. contentView.addSubview(oneButton)
  134. oneButton.snp.makeConstraints { make in
  135. make.size.equalTo(CGSize(width: 250.rpx, height: 44.rpx))
  136. make.centerX.equalToSuperview()
  137. make.bottom.equalTo(-54.rpx)
  138. }
  139. }
  140. }