jsdw_ios/QuickLocation/Section/Home/LocationPermissionPopView.s...

178 lines
5.1 KiB
Swift

//
// LocationPermissionPopView.swift
// QuickLocation
//
// Created by on 2026/7/8.
//
import UIKit
import RxSwift
import RxCocoa
class LocationPermissionPopView: UIView {
private static let shared = LocationPermissionPopView(frame: CGRect(origin: .zero, size: kScreenSize))
var disposeBag = DisposeBag()
static func show() {
guard let superView = kKeyWindow else {
return
}
if LocationPermissionPopView.shared.superview != nil {
LocationPermissionPopView.shared.removeFromSuperview()
LocationPermissionPopView.shared.bgView.frame = .zero
}
LocationPermissionPopView.shared.bgView.alpha = 1
LocationPermissionPopView.shared.bgView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
superView.addSubview(LocationPermissionPopView.shared)
superView.bringSubviewToFront(LocationPermissionPopView.shared)
UIView.animate(withDuration: 0.25) {
LocationPermissionPopView.shared.bgView.alpha = 1
}
}
///
static func dismiss() {
guard LocationPermissionPopView.shared.superview != nil else { return }
UIView.animate(withDuration: 0.25, delay: 0, options: [.curveEaseIn]) {
LocationPermissionPopView.shared.bgView.alpha = 0
} completion: { _ in
LocationPermissionPopView.shared.removeFromSuperview()
}
}
private func setupRx() {
settingBtn.rx.tap.subscribe(onNext: { _ in
guard let settingsURL = URL(string: UIApplication.openSettingsURLString) else { return }
LocationPermissionPopView.dismiss()
if UIApplication.shared.canOpenURL(settingsURL) {
UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
}
}).disposed(by: disposeBag)
closeBtn.rx.tap.subscribe(onNext: { _ in
LocationPermissionPopView.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 textImgView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFill
view.image = UIImage(named: "Home/permission_text")
return view
}()
lazy var settingBtn: 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
}()
lazy var closeBtn: 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
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(textImgView)
popBgView.addSubview(settingBtn)
popBgView.addSubview(closeBtn)
popView.layoutChain
.centerX()
.centerY()
.width(315)
.height(362)
popBgView.layoutChain.edges()
logoImgView.layoutChain
.left(16)
.top(-45)
.width(109)
.height(109)
headerBgImg.layoutChain
.edges(excludingEdge: .bottom)
.heightToWidth(100/315)
textImgView.layoutChain
.top(70)
.centerX()
.width(275)
.height(173)
closeBtn.layoutChain
.bottom()
.height(50)
.edgesHorzontal(20)
settingBtn.layoutChain
.bottomToTopOfView(closeBtn)
.height(50)
.edgesHorzontal(20)
setupRx()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
}
}