QSLHomeAddFriendAlertView.swift 5.9 KB

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