| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- //
- // QSLPrivacyAlertView.swift
- // QuickSearchLocation
- //
- // Created by Destiny on 2024/12/9.
- //
- import UIKit
- import YYText
- class QSLPrivacyAlertView: UIView {
-
- lazy var contentView: UIView = {
-
- let contentView = UIView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
- contentView.backgroundColor = .white
- contentView.addRadius(radius: 8.rpx)
- return contentView
- }()
-
- lazy var titleLabel: UILabel = {
-
- let label = UILabel()
- label.text("温馨提示")
- label.mediumFont(17)
- label.textColor = QSLColor.Color_202020
- return label
- }()
-
- lazy var contentLabel: YYLabel = {
-
- let label = YYLabel()
- label.textAlignment = .center
- label.numberOfLines = 0
-
- let attr = NSMutableAttributedString()
-
- let firstAttr = NSMutableAttributedString(string: "亲爱的用户,感谢您使用我们产品,为了更好的为您服务,我们可能向系统申请以下必要权限:定位信息权限、存储空间、电话权限等,用于应用的基本服务和功能),你有权拒绝或者撤回权限。 本软件非常重视您的隐私和个人信息,在您使用之前请仔细阅读")
- firstAttr.yy_lineSpacing = 5
- firstAttr.font(14)
- firstAttr.color(.hexStringColor(hexString: "#404040"))
- attr.append(firstAttr)
-
- let privacyHL = YYTextHighlight()
- let privacyText = NSMutableAttributedString(string: "《隐私权政策》")
- privacyText.yy_lineSpacing = 5
- privacyText.font(14)
- privacyText.color(.hexStringColor(hexString: "#2F79FF"))
- privacyText.yy_setTextHighlight(privacyHL, range: NSRange(location: 0, length: "《隐私权政策》".count))
- privacyHL.tapAction = { [weak self] containerView, text, range, rect in
- self?.privacyAction()
- }
- attr.append(privacyText)
- let andAttr = NSMutableAttributedString(string: "和")
- andAttr.yy_lineSpacing = 5
- andAttr.font(14)
- andAttr.color(.hexStringColor(hexString: "#404040"))
- attr.append(andAttr)
-
- let serviceHL = YYTextHighlight()
- let serviceText = NSMutableAttributedString(string: "《服务条款》")
- serviceText.yy_lineSpacing = 5
- serviceText.font(14)
- serviceText.color(.hexStringColor(hexString: "#2F79FF"))
- serviceText.yy_setTextHighlight(serviceHL, range: NSRange(location: 0, length: "《服务条款》".count))
- serviceHL.tapAction = { [weak self] containerView, text, range, rect in
- self?.serviceAction()
- }
- attr.append(serviceText)
-
- let remainAttr = NSMutableAttributedString(string: "全文,如您同意,请点击点击下方的“同意”按钮。")
- remainAttr.yy_lineSpacing = 5
- remainAttr.font(14)
- remainAttr.color(.hexStringColor(hexString: "#404040"))
- attr.append(remainAttr)
-
- label.attributedText = attr
-
- return label
- }()
-
- lazy var firstButton: UIButton = {
-
- let btn = UIButton()
- btn.backgroundColor = .hexStringColor(hexString: "#F8F8F8")
- btn.addRadius(radius: 20.rpx)
- btn.title("不同意")
- btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
- btn.mediumFont(16)
- btn.addTarget(self, action: #selector(firstBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var secondButton: UIButton = {
-
- let btn = UIButton()
- btn.addRadius(radius: 20.rpx)
- btn.title("同意")
- btn.textColor(.white)
- btn.mediumFont(16)
- btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 118.rpx, height: 40.rpx, direction: .horizontal)
- btn.addTarget(self, action: #selector(secondBtnAction), for: .touchUpInside)
- return btn
- }()
-
- var secondBtnClosure: (() -> ())?
-
- var serviceBlock: (() -> Void)?
-
- var privacyBlock: (() -> Void)?
-
- var isFirstClick: Bool = true
-
- class func alert(view: UIView,
- secondBtnClosure: @escaping () -> () = {}, serviceCloure: @escaping () -> Void, privacyClosure: @escaping () -> Void) {
-
- let window = QSLPrivacyAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
- window.secondBtnClosure = secondBtnClosure
- window.serviceBlock = serviceCloure
- window.privacyBlock = privacyClosure
- view.addSubview(window)
-
- QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_show)
-
- UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
- window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
- window.contentView.isHidden = false
- }
- }
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- initView()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- // 取消按钮点击事件
- @objc func firstBtnAction() {
- if isFirstClick {
- self.firstButton.title("不同意并退出")
- isFirstClick = false
- QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_disagree)
- } else {
- QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_second_disagree)
- exit(0)
- }
- }
-
- // 确认按钮点击事件
- @objc func secondBtnAction() {
- if isFirstClick {
- QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_agree)
- } else {
- QSEventHandle.eventPush(eventName: QSLGravityConst.privacy_second_agree)
- }
- if let secondBtnClosure = self.secondBtnClosure {
- secondBtnClosure()
- }
- removeView()
- }
-
- // 移除
- @objc func removeView() {
-
- UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
- self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
- self?.contentView.isHidden = true
- } completion: { [weak self] finished in
- self?.removeFromSuperview()
- }
- }
-
- @objc func privacyAction() {
-
- if let privacyBlock = self.privacyBlock {
- privacyBlock()
- }
- }
-
- @objc func serviceAction() {
-
- if let serviceBlock = self.serviceBlock {
- serviceBlock()
- }
- }
- }
- extension QSLPrivacyAlertView {
-
- func initView() {
-
- addSubview(contentView)
- contentView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW - 60.rpx, height: 330.0.rpx))
- make.center.equalToSuperview()
- }
-
- contentView.addSubview(titleLabel)
- titleLabel.snp.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.top.equalTo(24.rpx)
- }
-
- contentView.addSubview(contentLabel)
- contentLabel.snp.makeConstraints { make in
- make.left.equalTo(24.rpx)
- make.right.equalTo(-24.rpx)
- make.top.equalTo(55.rpx)
- make.height.equalTo(200.rpx)
- }
-
- contentView.addSubview(firstButton)
- firstButton.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
- make.left.equalTo(24.rpx)
- make.bottom.equalTo(-24.rpx)
- }
-
- contentView.addSubview(secondButton)
- secondButton.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 118.rpx, height: 40.rpx))
- make.right.equalTo(-24.rpx)
- make.bottom.equalTo(-24.rpx)
- }
- }
- }
|