QSLAddFriendSuccessAlertView.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // QSLAddFriendSuccessAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/9/23.
  6. //
  7. import UIKit
  8. class QSLAddFriendSuccessAlertView: UIView {
  9. lazy var contentView: UIView = {
  10. let contentViewW = QSLConst.qsl_kScreenW - 60.rpx
  11. let contentViewH = 298.0.rpx
  12. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: contentViewW, height: contentViewH))
  13. contentView.backgroundColor = .white
  14. contentView.addRadius(radius: 8.rpx)
  15. return contentView
  16. }()
  17. lazy var centerImage : UIImageView = {
  18. let centerImage = UIImageView()
  19. centerImage.contentMode = .scaleAspectFit
  20. centerImage.image = UIImage(named: "friends_alert_bg")
  21. return centerImage
  22. }()
  23. lazy var titleLabel: UILabel = {
  24. let label = UILabel()
  25. label.text("您已成功定位到好友!")
  26. label.mediumFont(20)
  27. label.textColor = QSLColor.textColor_333
  28. return label
  29. }()
  30. lazy var oneButton: UIButton = {
  31. let btn = UIButton()
  32. btn.addRadius(radius: 20.rpx)
  33. btn.title("立即查看")
  34. btn.textColor(.white)
  35. btn.mediumFont(16)
  36. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 150.rpx, height: 40.rpx, direction: .horizontal)
  37. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  38. return btn
  39. }()
  40. lazy var closeButton: UIButton = {
  41. let btn = UIButton()
  42. btn.setBackgroundImage(UIImage(named: "public_btn_close_AAA"), for: .normal)
  43. btn.addTarget(self, action: #selector(removeView), for: .touchUpInside)
  44. return btn
  45. }()
  46. var oneBtnClosure: (() -> ())?
  47. class func alert(view: UIView,
  48. clickBtnClosure: @escaping () -> () = {}) {
  49. let window = QSLAddFriendSuccessAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  50. view.addSubview(window)
  51. window.oneBtnClosure = clickBtnClosure
  52. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  53. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  54. window.contentView.isHidden = false
  55. }
  56. }
  57. override init(frame: CGRect) {
  58. super.init(frame: frame)
  59. initView()
  60. }
  61. required init?(coder: NSCoder) {
  62. fatalError("init(coder:) has not been implemented")
  63. }
  64. // 单按钮点击事件
  65. @objc func oneBtnAction() {
  66. if let oneBtnClosure = self.oneBtnClosure {
  67. oneBtnClosure()
  68. }
  69. removeView()
  70. }
  71. // 移除
  72. @objc func removeView() {
  73. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  74. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  75. self?.contentView.isHidden = true
  76. self?.centerImage.isHidden = true
  77. } completion: { [weak self] finished in
  78. self?.removeFromSuperview()
  79. }
  80. }
  81. }
  82. extension QSLAddFriendSuccessAlertView {
  83. func initView() {
  84. addSubview(contentView)
  85. contentView.snp.makeConstraints { make in
  86. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 298.0.rpx))
  87. make.center.equalToSuperview()
  88. }
  89. contentView.addSubview(centerImage)
  90. centerImage.snp.makeConstraints { make in
  91. make.size.equalTo(CGSize(width: 190.rpx, height: 175.rpx))
  92. make.centerX.equalToSuperview()
  93. make.top.equalTo(12.rpx)
  94. }
  95. contentView.addSubview(titleLabel)
  96. titleLabel.snp.makeConstraints { make in
  97. make.centerX.equalToSuperview()
  98. make.top.equalTo(192.rpx)
  99. }
  100. contentView.addSubview(closeButton)
  101. closeButton.snp.makeConstraints { make in
  102. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  103. make.top.equalTo(12.rpx)
  104. make.right.equalTo(-12.rpx)
  105. }
  106. contentView.addSubview(oneButton)
  107. oneButton.snp.makeConstraints { make in
  108. make.size.equalTo(CGSize(width: 150.rpx, height: 40.rpx))
  109. make.centerX.equalToSuperview()
  110. make.bottom.equalTo(-24.rpx)
  111. }
  112. }
  113. }