// // VipWaivePopView.swift // QuickLocation // // Created by 八条 on 2026/6/4. // import UIKit import RxSwift import RxCocoa class VipWaivePopView: UIView { private static let shared = VipWaivePopView(frame: CGRect(origin: .zero, size: kScreenSize)) var disposeBag = DisposeBag() static func show() { guard let superView = kKeyWindow else { return } if VipWaivePopView.shared.superview != nil { VipWaivePopView.shared.removeFromSuperview() VipWaivePopView.shared.bgView.frame = .zero } VipWaivePopView.shared.bgView.alpha = 1 VipWaivePopView.shared.bgView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight) superView.addSubview(VipWaivePopView.shared) superView.bringSubviewToFront(VipWaivePopView.shared) UIView.animate(withDuration: 0.25) { VipWaivePopView.shared.bgView.alpha = 1 } } /// 关闭 static func dismiss() { guard VipWaivePopView.shared.superview != nil else { return } UIView.animate(withDuration: 0.25, delay: 0, options: [.curveEaseIn]) { VipWaivePopView.shared.bgView.alpha = 0 } completion: { _ in VipWaivePopView.shared.removeFromSuperview() } } private func setupRx() { confirmBtn.rx.tap.subscribe(onNext: { _ in VipWaivePopView.dismiss() }).disposed(by: disposeBag) closeBtn.rx.tap.subscribe(onNext: { _ in VipWaivePopView.dismiss() AppRouter.shared.popOrDismiss() }).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 bgImgView: UIImageView = { let view = UIImageView() view.image = UIImage(named: "VipRecharge/waive_bg") view.contentMode = .scaleAspectFill return view }() lazy var confirmBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("确认开通", for: .normal) btn.setTitleColor(.white, for: .normal) btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .bold) // btn.backgroundColor = UIColor(hexStr: "#00ADFE") // btn.setBackgroundImage(UIImage(named: "Common/gradient_bg"), for: .normal) btn.cornerRadius = 25 return btn }() lazy var closeBtn: UIButton = { let btn = UIButton(type: .custom) btn.setTitle("残忍放弃", for: .normal) btn.setTitleColor(UIColor(hexStr: "#00ADFE"), for: .normal) btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) btn.backgroundColor = .white btn.borderWidth = 1 btn.borderColor = UIColor(hexStr: "#00ADFE") btn.cornerRadius = 25 return btn }() // MARK: - Init override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .clear addSubview(bgView) bgView.addSubview(popView) popView.addSubview(bgImgView) popView.addSubview(confirmBtn) popView.addSubview(closeBtn) popView.layoutChain .centerY() .edgesHorzontal(30) .heightToWidth(389/315) bgImgView.layoutChain.edges() closeBtn.layoutChain .left(18) .bottom(18) .width(100) .height(50) confirmBtn.layoutChain .topToView(closeBtn) .leftToRightOfView(closeBtn, offset: 19) .right(18) .height(50) setupRx() self.layoutIfNeeded() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() popView.layoutIfNeeded() confirmBtn.setGradientLayer(frame: confirmBtn.bounds, startPoint: CGPoint(x: 0.5, y: 0.5), endPoint: CGPoint(x: 1, y: 0), colors: [UIColor(hexStr: "#00ADFE"), UIColor(hexStr: "#46C8FF")], locations: [0.1, 1]) } }