jsdw_ios/QuickLocation/Section/Mine/Account/CancellationPopView.swift

262 lines
7.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// CancellationPopView.swift
// QuickLocation
//
// Created by on 2026/6/11.
//
import UIKit
import RxSwift
import RxCocoa
class CancellationPopView: UIView {
private static let shared = CancellationPopView(frame: CGRect(origin: .zero, size: kScreenSize))
var disposeBag = DisposeBag()
private var completion: (() -> Void)?
static func show(completion: @escaping (() -> Void)) {
guard let superView = kKeyWindow else {
return
}
if CancellationPopView.shared.superview != nil {
CancellationPopView.shared.removeFromSuperview()
CancellationPopView.shared.bgView.frame = .zero
}
CancellationPopView.shared.bgView.alpha = 1
CancellationPopView.shared.bgView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
superView.addSubview(CancellationPopView.shared)
superView.bringSubviewToFront(CancellationPopView.shared)
UIView.animate(withDuration: 0.25) {
CancellationPopView.shared.bgView.alpha = 1
}
CancellationPopView.shared.completion = {
completion()
CancellationPopView.dismiss()
}
}
///
static func dismiss() {
guard CancellationPopView.shared.superview != nil else { return }
UIView.animate(withDuration: 0.25, delay: 0, options: [.curveEaseIn]) {
CancellationPopView.shared.bgView.alpha = 0
} completion: { _ in
CancellationPopView.shared.removeFromSuperview()
}
}
private func setupRx() {
checkBox.rx.tap
.subscribe(onNext: { [weak self] in
guard let self = self else { return }
self.checkBox.isSelected = !self.checkBox.isSelected
self.confirmBtn.isEnabled = self.checkBox.isSelected
})
.disposed(by: disposeBag)
agreementLab.rx.tapGesture.subscribe { _ in
CancellationPopView.dismiss()
AppRouter.push(Route.web, userInfo: ["url": URLManager.shared.cancellationNoticeUrl])
}.disposed(by: disposeBag)
confirmBtn.rx.tap.subscribe(onNext: { _ in
self.completion?()
}).disposed(by: disposeBag)
closeBtn.rx.tap.subscribe(onNext: { _ in
CancellationPopView.dismiss()
}).disposed(by: disposeBag)
}
private lazy var bgView: UIView = {
let view = UIView()
view.backgroundColor = .black.withAlphaComponent(0.5)
return view
}()
lazy var popView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var popBgView: UIView = {
let view = UIView()
view.backgroundColor = .white
view.cornerRadius = 30
return view
}()
lazy var logoImgView: UIImageView = {
let view = UIImageView(image: UIImage(named: "Popup/bell"))
return view
}()
lazy var headerBgImg: UIImageView = {
let view = UIImageView(image: UIImage(named: "Popup/header_bg"))
view.contentMode = .scaleAspectFill
return view
}()
lazy var titleLab: UILabel = {
let label = UILabel()
label.text = "删除账户"
label.font = .systemFont(ofSize: 20, weight: .semibold)
label.textColor = UIColor(hexStr: "#0F2846")
label.textAlignment = .center
label.numberOfLines = 0
return label
}()
lazy var contentLab: UILabel = {
let label = UILabel()
label.text = "申请删除账号后账号将在15日后自动删除若在15日内登录账号删除账号申请将被取消您确定要删除吗"
label.font = .systemFont(ofSize: 14, weight: .medium)
label.textColor = UIColor(hexStr: "#333333")
label.textAlignment = .center
label.numberOfLines = 0
return label
}()
lazy var agreementView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.addSubview(checkBox)
checkBox.layoutChain
.left()
.width(12)
.height(12)
.centerY()
view.addSubview(agreementLab)
agreementLab.layoutChain
.leftToRightOfView(checkBox, offset: 5)
.edgesVertical()
.right()
return view
}()
lazy var checkBox: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "Login/checkbox"), for: .normal)
btn.setImage(UIImage(named: "Login/selected"), for: .selected)
btn.extendEdgeInsets = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 0)
return btn
}()
lazy var agreementLab: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 10, weight: .medium)
label.textColor = UIColor(hexStr: "#333333")
label.isUserInteractionEnabled = true
let text = "阅读并同意《账号注销协议》"
let attr = NSMutableAttributedString(string: text)
let range = (text as NSString).range(of: "《账号注销协议》")
attr.addAttribute(.foregroundColor, value: UIColor(hexStr: "#FFC006"), range: range)
label.attributedText = attr
return label
}()
lazy var confirmBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("确认", for: .normal)
btn.setTitleColor(UIColor(hexStr: "#16B3FF"), for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.backgroundColor = .clear
btn.isEnabled = false
return btn
}()
lazy var closeBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("取消", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal)
btn.cornerRadius = 25
return btn
}()
// MARK: - Init
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .clear
addSubview(bgView)
bgView.addSubview(popView)
popView.addSubview(popBgView)
popView.addSubview(logoImgView)
popBgView.addSubview(headerBgImg)
popBgView.addSubview(titleLab)
popBgView.addSubview(contentLab)
popBgView.addSubview(agreementView)
popBgView.addSubview(closeBtn)
popBgView.addSubview(confirmBtn)
popView.layoutChain
.centerY()
.centerX()
.width(315)
popBgView.layoutChain.edges()
logoImgView.layoutChain
.left(16)
.top(-45)
.width(109)
.height(109)
headerBgImg.layoutChain
.edges(excludingEdge: .bottom)
.heightToWidth(100/315)
titleLab.layoutChain
.top(53)
.centerX()
contentLab.layoutChain
.topToBottomOfView(titleLab, offset: 10)
.edgesHorzontal(20)
agreementView.layoutChain
.topToBottomOfView(contentLab, offset: 24)
.centerX()
.height(14)
closeBtn.layoutChain
.topToBottomOfView(agreementView, offset: 20)
.edgesHorzontal(20)
.height(50)
confirmBtn.layoutChain
.topToBottomOfView(closeBtn, offset: 10)
.edgesHorzontal(20)
.height(50)
.bottom(10)
setupRx()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
}
}