217 lines
6.1 KiB
Swift
217 lines
6.1 KiB
Swift
//
|
||
// LockDistractPermissionPopView.swift
|
||
// QuickLocation
|
||
//
|
||
|
||
import UIKit
|
||
import RxSwift
|
||
import RxCocoa
|
||
|
||
final class LockDistractPermissionPopView: UIView {
|
||
|
||
private static let shared = LockDistractPermissionPopView(frame: CGRect(origin: .zero, size: kScreenSize))
|
||
|
||
private var disposeBag = DisposeBag()
|
||
|
||
static func show() {
|
||
guard let superView = kKeyWindow else { return }
|
||
let pop = LockDistractPermissionPopView.shared
|
||
if pop.superview != nil {
|
||
pop.removeFromSuperview()
|
||
}
|
||
pop.frame = superView.bounds
|
||
pop.alpha = 0
|
||
superView.addSubview(pop)
|
||
superView.bringSubviewToFront(pop)
|
||
pop.layoutIfNeeded()
|
||
UIView.animate(withDuration: 0.25) {
|
||
pop.alpha = 1
|
||
}
|
||
}
|
||
|
||
static func dismiss() {
|
||
guard shared.superview != nil else { return }
|
||
UIView.animate(withDuration: 0.2, delay: 0, options: [.curveEaseIn]) {
|
||
shared.alpha = 0
|
||
} completion: { _ in
|
||
shared.removeFromSuperview()
|
||
}
|
||
}
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
setupUI()
|
||
bind()
|
||
}
|
||
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
private func bind() {
|
||
knowBtn.rx.tap
|
||
.subscribe(onNext: { _ in
|
||
LockDistractPermissionPopView.dismiss()
|
||
})
|
||
.disposed(by: disposeBag)
|
||
|
||
let tap = UITapGestureRecognizer(target: self, action: #selector(tapMask))
|
||
tap.delegate = self
|
||
addGestureRecognizer(tap)
|
||
}
|
||
|
||
@objc private func tapMask() {
|
||
LockDistractPermissionPopView.dismiss()
|
||
}
|
||
|
||
private func setupUI() {
|
||
addSubview(dimView)
|
||
addSubview(card)
|
||
addSubview(birdView)
|
||
card.addSubview(gradientView)
|
||
card.addSubview(titleLab)
|
||
card.addSubview(row1)
|
||
card.addSubview(row2)
|
||
card.addSubview(pathLab)
|
||
card.addSubview(knowBtn)
|
||
|
||
dimView.layoutChain.edges()
|
||
|
||
card.layoutChain
|
||
.centerY()
|
||
.edgesHorzontal(38)
|
||
|
||
birdView.layoutChain
|
||
.bottomToTopOfView(card, offset: 28)
|
||
.centerX()
|
||
.width(120)
|
||
.height(88)
|
||
|
||
gradientView.layoutChain
|
||
.top()
|
||
.edgesHorzontal()
|
||
.height(72)
|
||
|
||
titleLab.layoutChain
|
||
.top(36)
|
||
.centerX()
|
||
|
||
row1.layoutChain
|
||
.topToBottomOfView(titleLab, offset: 20)
|
||
.left(22)
|
||
.right(22)
|
||
|
||
row2.layoutChain
|
||
.topToBottomOfView(row1, offset: 14)
|
||
.left(22)
|
||
.right(22)
|
||
|
||
pathLab.layoutChain
|
||
.topToBottomOfView(row2, offset: 8)
|
||
.left(40)
|
||
.right(22)
|
||
|
||
knowBtn.layoutChain
|
||
.topToBottomOfView(pathLab, offset: 22)
|
||
.edgesHorzontal(20)
|
||
.height(48)
|
||
.bottom(20)
|
||
}
|
||
|
||
private lazy var dimView: UIView = {
|
||
let view = UIView()
|
||
view.backgroundColor = UIColor.black.withAlphaComponent(0.55)
|
||
return view
|
||
}()
|
||
|
||
private lazy var card: UIView = {
|
||
let view = UIView()
|
||
view.backgroundColor = .white
|
||
view.layer.cornerRadius = 28
|
||
view.clipsToBounds = true
|
||
return view
|
||
}()
|
||
|
||
private lazy var gradientView: UIView = {
|
||
GradientHostView()
|
||
}()
|
||
|
||
private lazy var birdView: UIImageView = {
|
||
let iv = UIImageView(image: UIImage(named: "LockDistract/horn_bird"))
|
||
iv.contentMode = .scaleAspectFit
|
||
return iv
|
||
}()
|
||
|
||
private lazy var titleLab: UILabel = {
|
||
let lab = UILabel()
|
||
lab.text = "锁定权限说明"
|
||
lab.font = FontManager.boboBold(20)
|
||
lab.textColor = UIColor(hexStr: "#293445")
|
||
return lab
|
||
}()
|
||
|
||
private lazy var row1: UIView = {
|
||
makeBulletRow("需要Ta开启App配对权限,不然无法锁定")
|
||
}()
|
||
|
||
private lazy var row2: UIView = {
|
||
makeBulletRow("权限开启位置")
|
||
}()
|
||
|
||
private lazy var pathLab: UILabel = {
|
||
let lab = UILabel()
|
||
lab.text = "【我的】 – 【权限检测】 – 【配对设置】"
|
||
lab.font = .systemFont(ofSize: 13, weight: .medium)
|
||
lab.textColor = UIColor(hexStr: "#8A94A6")
|
||
lab.numberOfLines = 0
|
||
return lab
|
||
}()
|
||
|
||
private lazy var knowBtn: UIButton = {
|
||
let btn = UIButton(type: .custom)
|
||
btn.setTitle("我知道了", for: .normal)
|
||
btn.setTitleColor(.white, for: .normal)
|
||
btn.titleLabel?.font = FontManager.boboBold(16)
|
||
btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal)
|
||
btn.cornerRadius = 16
|
||
return btn
|
||
}()
|
||
|
||
private func makeBulletRow(_ text: String) -> UIView {
|
||
let row = UIView()
|
||
let star = UIImageView(image: UIImage(named: "LockDistract/section_star"))
|
||
star.contentMode = .scaleAspectFit
|
||
let lab = UILabel()
|
||
lab.text = text
|
||
lab.font = .systemFont(ofSize: 14, weight: .medium)
|
||
lab.textColor = UIColor(hexStr: "#293445")
|
||
lab.numberOfLines = 0
|
||
row.addSubview(star)
|
||
row.addSubview(lab)
|
||
star.layoutChain.left().top(2).width(12).height(12)
|
||
lab.layoutChain.leftToRightOfView(star, offset: 6).right().top().bottom()
|
||
return row
|
||
}
|
||
}
|
||
|
||
private final class GradientHostView: UIView {
|
||
override class var layerClass: AnyClass { CAGradientLayer.self }
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
guard let layer = layer as? CAGradientLayer else { return }
|
||
layer.colors = [
|
||
UIColor(hexStr: "#E7FFF2").cgColor,
|
||
UIColor.white.cgColor
|
||
]
|
||
layer.startPoint = CGPoint(x: 0.5, y: 0)
|
||
layer.endPoint = CGPoint(x: 0.5, y: 1)
|
||
}
|
||
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
}
|
||
|
||
extension LockDistractPermissionPopView: UIGestureRecognizerDelegate {
|
||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
||
!card.frame.contains(touch.location(in: self))
|
||
}
|
||
}
|