QSLHomeAddFriendAlertView.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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("查找好友")
  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. class func alert(view: UIView,
  55. clickBtnClosure: @escaping () -> () = {}) {
  56. let window = QSLHomeAddFriendView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  57. view.addSubview(window)
  58. window.oneBtnClosure = clickBtnClosure
  59. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  60. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  61. window.contentView.isHidden = false
  62. }
  63. }
  64. override init(frame: CGRect) {
  65. super.init(frame: frame)
  66. initView()
  67. }
  68. required init?(coder: NSCoder) {
  69. fatalError("init(coder:) has not been implemented")
  70. }
  71. // 单按钮点击事件
  72. @objc func oneBtnAction() {
  73. if let oneBtnClosure = self.oneBtnClosure {
  74. oneBtnClosure()
  75. }
  76. removeView()
  77. }
  78. // 移除
  79. @objc func removeView() {
  80. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  81. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  82. self?.contentView.isHidden = true
  83. self?.centerImage.isHidden = true
  84. } completion: { [weak self] finished in
  85. self?.removeFromSuperview()
  86. }
  87. }
  88. }
  89. extension QSLHomeAddFriendView {
  90. func initView() {
  91. addSubview(contentView)
  92. contentView.snp.makeConstraints { make in
  93. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW, height: 365.0.rpx))
  94. make.center.equalToSuperview()
  95. }
  96. contentView.addSubview(centerImage)
  97. centerImage.snp.makeConstraints { make in
  98. make.top.bottom.left.right.equalTo(0)
  99. }
  100. contentView.addSubview(titleLabel)
  101. titleLabel.snp.makeConstraints { make in
  102. make.left.equalTo(54.rpx)
  103. make.right.equalTo(-54.rpx)
  104. make.top.equalTo(22.rpx)
  105. make.height.equalTo(42.rpx)
  106. }
  107. contentView.addSubview(contentLabel)
  108. contentLabel.snp.makeConstraints { make in
  109. make.left.equalTo(54.rpx)
  110. make.right.equalTo(-54.rpx)
  111. make.top.equalTo(titleLabel.snp.bottom)
  112. make.height.equalTo(14.rpx)
  113. }
  114. contentView.addSubview(hideButton)
  115. hideButton.snp.makeConstraints { make in
  116. make.size.equalTo(CGSize(width: 60.rpx, height: 28.rpx))
  117. make.centerX.equalToSuperview()
  118. make.bottom.equalTo(-18.rpx)
  119. }
  120. contentView.addSubview(oneButton)
  121. oneButton.snp.makeConstraints { make in
  122. make.size.equalTo(CGSize(width: 250.rpx, height: 44.rpx))
  123. make.centerX.equalToSuperview()
  124. make.bottom.equalTo(-54.rpx)
  125. }
  126. }
  127. }