-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlurView.swift
More file actions
89 lines (70 loc) · 2.77 KB
/
BlurView.swift
File metadata and controls
89 lines (70 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// BlurView.swift
// BlurViewTest
//
// Created by hanwe lee on 2020/12/30.
// Copyright © 2020 hanwe. All rights reserved.
//
import SnapKit
import Then
protocol SecureInactiveView where Self: UIViewController {
func registSecureCoverView()
}
private var secureInactiveViewAssociatedObjectKey: Void?
extension SecureInactiveView {
private var secureCoverView: SecureInactiveCoverView {
get {
var coverView = objc_getAssociatedObject(self, &secureInactiveViewAssociatedObjectKey) as? SecureInactiveCoverView
if coverView == nil {
coverView = SecureInactiveCoverView()
objc_setAssociatedObject(self, &secureInactiveViewAssociatedObjectKey, coverView, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
return coverView ?? SecureInactiveCoverView()
}
set {
objc_setAssociatedObject(self, &secureInactiveViewAssociatedObjectKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
func registSecureCoverView() {
NotificationCenter.default.addObserver(forName: Notification.Name(NotificationDefine.APP_DID_BECOME_ACTIVE_NOTIFICATION_DEFINE), object: nil, queue: nil) { [unowned self] notification in
becomeActive(notification: notification)
}
NotificationCenter.default.addObserver(forName: Notification.Name(NotificationDefine.APP_WILL_RESIGN_ACTIVE_NOTIFICATION_DEFINE), object: nil, queue: nil) { [unowned self] notification in
resignActive(notification: notification)
}
self.view.addSubview(secureCoverView)
self.secureCoverView.snp.makeConstraints {
$0.edges.equalTo(self.view)
}
self.secureCoverView.isHidden = true
}
private func becomeActive(notification: Notification) {
self.secureCoverView.isHidden = true
}
private func resignActive(notification: Notification) {
self.secureCoverView.isHidden = false
}
}
class SecureInactiveCoverView: UIView {
// MARK: private UI property
// MARK: internal UI property
// MARK: private property
// MARK: property
// MARK: lifeCycle
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
init() {
super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
makeBlurView()
}
// MARK: private func
private func makeBlurView() {
let blurEffect = UIBlurEffect(style: .regular)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview(blurEffectView)
}
// MARK: func
}