CNLiveLoginAuthView.swift 10.1 KB
//
//  CNLiveLoginAuthView.swift
//  metaCode
//
//  Created by open on 2023/6/6.
//

import Foundation

class LoginAuthTipView: UIView {
    
}

class LoginAuthInfoView : UIView {
    
    lazy var imageView : UIImageView = {
        let imageView = UIImageView.init()
        imageView.contentMode = .scaleToFill
        imageView.backgroundColor = .clear
        imageView.isUserInteractionEnabled = true
        imageView.image = UIImage(named: "login_body_show_auth_back")
        return imageView
    }()
    
    lazy var appLabel : UILabel = {
        let appLabel = UILabel.init()
        appLabel.text = "APP"
        appLabel.textColor = .white
        appLabel.backgroundColor = .black
        appLabel.font = BoldFont_16_Fit
        appLabel.textAlignment = .center
        appLabel.layer.cornerRadius = 10
        appLabel.clipsToBounds = true
        return appLabel
    }()
    
    lazy var titleLabel : UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.text = "个人信息保护政策"
        titleLabel.font = BoldFont_17_Fit
        titleLabel.textAlignment = .left
        titleLabel.textColor = .black
        titleLabel.backgroundColor = .clear
        return titleLabel
    }()
    
    lazy var contentView : UIImageView = {
        let contentView = UIImageView.init()
        contentView.backgroundColor = .clear
        contentView.image = UIImage(named: "login_body_show_auth_content")
        contentView.contentMode = .scaleToFill
        return contentView
    }()
    
    lazy var agreeBtn: UIButton = {
        let agreeBtn = UIButton.init(type: .custom)
        agreeBtn.setTitle("同 意", for: .normal)
        agreeBtn.titleLabel?.font = BoldFont_15_Fit
        agreeBtn.layer.cornerRadius = 20
        agreeBtn.layer.masksToBounds = true
        agreeBtn.setTitleColor(.white, for: .normal)
        agreeBtn.addTarget(self, action: #selector(agreeAction), for: .touchUpInside)
        return agreeBtn
    }()
    
    lazy var agreeNotBtn: UIButton = {
        let agreeNotBtn = UIButton(type: .custom)
        agreeNotBtn.setTitle("不同意", for: .normal)
        agreeNotBtn.titleLabel?.font = BoldFont_15_Fit
        agreeNotBtn.layer.cornerRadius = 20
        agreeNotBtn.layer.masksToBounds = true
        agreeNotBtn.layer.borderColor = HexColor("#979797")?.cgColor
        agreeNotBtn.layer.borderWidth = 1
        agreeNotBtn.setTitleColor(.black, for: .normal)
        agreeNotBtn.addTarget(self, action: #selector(agreeNotAction), for: .touchUpInside)
        return agreeNotBtn
    }()
    
    
    static func showAuthView() {
        let authView = LoginAuthInfoView()
        
        let window = UIApplication.shared.windows.last
        window?.addSubview(authView)
        authView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        window?.layoutIfNeeded()
        authView.alpha = 0
        UIView.animate(withDuration: 0.1) {
            authView.alpha = 1
        } completion: { _ in
            authView.layoutIfNeeded()
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.black.withAlphaComponent(0.2)
        
        addSubview(imageView)
        imageView.addSubview(appLabel)
        imageView.addSubview(titleLabel)
        imageView.addSubview(contentView)
        imageView.addSubview(agreeBtn)
        imageView.addSubview(agreeNotBtn)
        
        setupConstraints()
        agreeBtn.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupConstraints() {
        imageView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.equalToSuperview().offset(30)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo(420)
        }
        appLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(20)
            make.left.equalToSuperview().offset(20)
            make.height.equalTo(20)
            make.width.equalTo(45)
        }
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(appLabel.snp.bottom).offset(10)
            make.left.equalToSuperview().offset(20)
        }
        contentView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(20)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
        }
        agreeBtn.snp.makeConstraints { make in
            make.right.equalTo(imageView.snp.right).offset(-20)
            make.bottom.equalTo(imageView.snp.bottom).offset(-20)
            make.width.equalTo((KSreenWidth - 140) * 0.6)
            make.height.equalTo(40)
        }
        agreeNotBtn.snp.makeConstraints { make in
            make.centerY.equalTo(agreeBtn)
            make.left.equalToSuperview().offset(20)
            make.width.equalTo((KSreenWidth - 140) * 0.4)
            make.height.equalTo(40)
        }
    }
    
    deinit {
        
    }
    
    @objc func agreeNotAction() {
        removeFromSuperview()
        LoginAuthPollicyView.showAuthView()
    }
    
    @objc func agreeAction() {
        removeFromSuperview()
    }
    
}


class LoginAuthPollicyView : UIView {

    lazy var backView: UIView = {
        let backView = UIView.init()
        backView.backgroundColor = HexColor("#F4F7FE")
        backView.layer.cornerRadius = 8
        backView.isUserInteractionEnabled = true
        backView.layer.masksToBounds = true
        return backView
    }()

    lazy var titleLabel : UILabel = {
        let titleLabel = UILabel.init()
        titleLabel.text = "需要同意政策才能继续使用"
        titleLabel.font = BoldFont_17_Fit
        titleLabel.textAlignment = .center
        titleLabel.textColor = .black
        titleLabel.backgroundColor = .clear
        return titleLabel
    }()

    lazy var contentView : UIImageView = {
        let contentView = UIImageView.init()
        contentView.backgroundColor = .clear
        contentView.image = UIImage(named: "login_body_show_auth_policy")
        contentView.contentMode = .scaleToFill
        return contentView
    }()

    lazy var agreeBtn: UIButton = {
        let agreeBtn = UIButton.init(type: .custom)
        agreeBtn.setTitle("再次查看", for: .normal)
        agreeBtn.titleLabel?.font = BoldFont_15_Fit
        agreeBtn.layer.cornerRadius = 20
        agreeBtn.layer.masksToBounds = true
        agreeBtn.setTitleColor(.white, for: .normal)
        agreeBtn.addTarget(self, action: #selector(agreeAction), for: .touchUpInside)
        return agreeBtn
    }()

    lazy var agreeNotBtn: UIButton = {
        let agreeNotBtn = UIButton(type: .custom)
        agreeNotBtn.setTitle("退出应用", for: .normal)
        agreeNotBtn.titleLabel?.font = BoldFont_15_Fit
        agreeNotBtn.layer.cornerRadius = 20
        agreeNotBtn.layer.masksToBounds = true
        agreeNotBtn.layer.borderColor = HexColor("#979797")?.cgColor
        agreeNotBtn.layer.borderWidth = 1
        agreeNotBtn.setTitleColor(.black, for: .normal)
        agreeNotBtn.addTarget(self, action: #selector(agreeNotAction), for: .touchUpInside)
        return agreeNotBtn
    }()

    static func showAuthView() {
        let authView = LoginAuthPollicyView.init()

        let window = UIApplication.shared.windows.last
        window?.addSubview(authView)
        authView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        window?.layoutIfNeeded()
        authView.alpha = 0
        UIView.animate(withDuration: 0.1) {
            authView.alpha = 1
        } completion: { _ in

        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.black.withAlphaComponent(0.2)

        addSubview(backView)
        backView.addSubview(titleLabel)
        backView.addSubview(contentView)
        backView.addSubview(agreeBtn)
        backView.addSubview(agreeNotBtn)

        setupConstraints()
        agreeBtn.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupConstraints() {
        backView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.equalToSuperview().offset(30)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo((KSreenWidth - 60) * 0.7)
        }
        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        contentView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(20)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
        }
        agreeBtn.snp.makeConstraints { make in
            make.right.equalTo(backView.snp.right).offset(-20)
            make.bottom.equalTo(backView.snp.bottom).offset(-20)
            make.width.equalTo((KSreenWidth - 140) * 0.6)
            make.height.equalTo(40)
        }
        agreeNotBtn.snp.makeConstraints { make in
            make.centerY.equalTo(agreeBtn)
            make.left.equalToSuperview().offset(20)
            make.width.equalTo((KSreenWidth - 140) * 0.4)
            make.height.equalTo(40)
        }
    }

    deinit {

    }

    @objc func agreeNotAction() {
        //退出应用
        UIControl().sendAction(#selector(NSXPCConnection.suspend), to: UIApplication.shared, for: nil)
    }

    @objc func agreeAction() {
        removeFromSuperview()
        LoginAuthInfoView.showAuthView()
    }

}