QSLPrivacyAlertView.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // QSLPrivacyAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/9.
  6. //
  7. import UIKit
  8. import YYText
  9. class QSLPrivacyAlertView: UIView {
  10. lazy var contentView: UIView = {
  11. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
  12. contentView.backgroundColor = .white
  13. contentView.addRadius(radius: 8.rpx)
  14. return contentView
  15. }()
  16. lazy var titleLabel: UILabel = {
  17. let label = UILabel()
  18. label.text("温馨提示")
  19. label.mediumFont(17)
  20. label.textColor = QSLColor.Color_202020
  21. return label
  22. }()
  23. lazy var contentLabel: YYLabel = {
  24. let label = YYLabel()
  25. label.textAlignment = .center
  26. label.numberOfLines = 0
  27. let attr = NSMutableAttributedString()
  28. let firstAttr = NSMutableAttributedString(string: "亲爱的用户,感谢您使用我们产品,为了更好的为您服务,我们可能向系统申请以下必要权限:定位信息权限、存储空间、电话权限等,用于应用的基本服务和功能),你有权拒绝或者撤回权限。 本软件非常重视您的隐私和个人信息,在您使用之前请仔细阅读")
  29. firstAttr.yy_lineSpacing = 5
  30. firstAttr.font(14)
  31. firstAttr.color(.hexStringColor(hexString: "#404040"))
  32. attr.append(firstAttr)
  33. let privacyHL = YYTextHighlight()
  34. let privacyText = NSMutableAttributedString(string: "《隐私权政策》")
  35. privacyText.yy_lineSpacing = 5
  36. privacyText.font(14)
  37. privacyText.color(.hexStringColor(hexString: "#2F79FF"))
  38. privacyText.yy_setTextHighlight(privacyHL, range: NSRange(location: 0, length: "《隐私权政策》".count))
  39. privacyHL.tapAction = { [weak self] containerView, text, range, rect in
  40. self?.privacyAction()
  41. }
  42. attr.append(privacyText)
  43. let andAttr = NSMutableAttributedString(string: "和")
  44. andAttr.yy_lineSpacing = 5
  45. andAttr.font(14)
  46. andAttr.color(.hexStringColor(hexString: "#404040"))
  47. attr.append(andAttr)
  48. let serviceHL = YYTextHighlight()
  49. let serviceText = NSMutableAttributedString(string: "《服务条款》")
  50. serviceText.yy_lineSpacing = 5
  51. serviceText.font(14)
  52. serviceText.color(.hexStringColor(hexString: "#2F79FF"))
  53. serviceText.yy_setTextHighlight(serviceHL, range: NSRange(location: 0, length: "《服务条款》".count))
  54. serviceHL.tapAction = { [weak self] containerView, text, range, rect in
  55. self?.serviceAction()
  56. }
  57. attr.append(serviceText)
  58. let remainAttr = NSMutableAttributedString(string: "全文,如您同意,请点击点击下方的“同意”按钮。")
  59. remainAttr.yy_lineSpacing = 5
  60. remainAttr.font(14)
  61. remainAttr.color(.hexStringColor(hexString: "#404040"))
  62. attr.append(remainAttr)
  63. label.attributedText = attr
  64. return label
  65. }()
  66. lazy var firstButton: UIButton = {
  67. let btn = UIButton()
  68. btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
  69. btn.addRadius(radius: 20.rpx)
  70. btn.title("不同意")
  71. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  72. btn.mediumFont(16)
  73. btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
  74. return btn
  75. }()
  76. lazy var secondButton: UIButton = {
  77. let btn = UIButton()
  78. btn.addRadius(radius: 20.rpx)
  79. btn.title("同意")
  80. btn.textColor(.white)
  81. btn.mediumFont(16)
  82. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
  83. btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
  84. return btn
  85. }()
  86. var secondBtnClosure: (() -> ())?
  87. var serviceBlock: (() -> Void)?
  88. var privacyBlock: (() -> Void)?
  89. var isFirstClick: Bool = true
  90. class func alert(view: UIView,
  91. secondBtnClosure: @escaping () -> () = {}, serviceCloure: @escaping () -> Void, privacyClosure: @escaping () -> Void) {
  92. let window = QSLPrivacyAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  93. window.secondBtnClosure = secondBtnClosure
  94. window.serviceBlock = serviceCloure
  95. window.privacyBlock = privacyClosure
  96. view.addSubview(window)
  97. QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_show)
  98. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  99. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  100. window.contentView.isHidden = false
  101. }
  102. }
  103. override init(frame: CGRect) {
  104. super.init(frame: frame)
  105. initView()
  106. }
  107. required init?(coder: NSCoder) {
  108. fatalError("init(coder:) has not been implemented")
  109. }
  110. // 取消按钮点击事件
  111. @objc func firstBtnAction() {
  112. if isFirstClick {
  113. self.firstButton.title("不同意并退出")
  114. isFirstClick = false
  115. QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_disagree)
  116. } else {
  117. QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_second_disagree)
  118. exit(0)
  119. }
  120. }
  121. // 确认按钮点击事件
  122. @objc func secondBtnAction() {
  123. if isFirstClick {
  124. QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_agree)
  125. } else {
  126. QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_second_agree)
  127. }
  128. if let secondBtnClosure = self.secondBtnClosure {
  129. secondBtnClosure()
  130. }
  131. removeView()
  132. }
  133. // 移除
  134. @objc func removeView() {
  135. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  136. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  137. self?.contentView.isHidden = true
  138. } completion: { [weak self] finished in
  139. self?.removeFromSuperview()
  140. }
  141. }
  142. @objc func privacyAction() {
  143. if let privacyBlock = self.privacyBlock {
  144. privacyBlock()
  145. }
  146. }
  147. @objc func serviceAction() {
  148. if let serviceBlock = self.serviceBlock {
  149. serviceBlock()
  150. }
  151. }
  152. }
  153. extension QSLPrivacyAlertView {
  154. func initView() {
  155. addSubview(contentView)
  156. contentView.snp.makeConstraints { make in
  157. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 330.0.rpx))
  158. make.center.equalToSuperview()
  159. }
  160. contentView.addSubview(titleLabel)
  161. titleLabel.snp.makeConstraints { make in
  162. make.centerX.equalToSuperview()
  163. make.top.equalTo(24.rpx)
  164. }
  165. contentView.addSubview(contentLabel)
  166. contentLabel.snp.makeConstraints { make in
  167. make.left.equalTo(24.rpx)
  168. make.right.equalTo(-24.rpx)
  169. make.top.equalTo(55.rpx)
  170. make.height.equalTo(200.rpx)
  171. }
  172. contentView.addSubview(firstButton)
  173. firstButton.snp.makeConstraints { make in
  174. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  175. make.left.equalTo(24.rpx)
  176. make.bottom.equalTo(-24.rpx)
  177. }
  178. contentView.addSubview(secondButton)
  179. secondButton.snp.makeConstraints { make in
  180. make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
  181. make.right.equalTo(-24.rpx)
  182. make.bottom.equalTo(-24.rpx)
  183. }
  184. }
  185. }