forked from yankodimitrov/SwiftPasscodeLock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasscodeLockPresenter.swift
More file actions
77 lines (55 loc) · 2.16 KB
/
Copy pathPasscodeLockPresenter.swift
File metadata and controls
77 lines (55 loc) · 2.16 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
//
// PasscodeLockPresenter.swift
// PasscodeLock
//
// Created by Yanko Dimitrov on 8/29/15.
// Copyright © 2015 Yanko Dimitrov. All rights reserved.
//
import UIKit
public class PasscodeLockPresenter {
private var mainWindow: UIWindow?
private lazy var passcodeLockWindow: UIWindow = {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.windowLevel = 0
window.makeKeyAndVisible()
return window
}()
private let passcodeConfiguration: PasscodeLockConfigurationType
private var isPasscodePresented = false
public init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType) {
mainWindow = window
mainWindow?.windowLevel = 1
passcodeConfiguration = configuration
}
public func presentPasscodeLock() {
guard passcodeConfiguration.repository.hasPasscode else { return }
guard !isPasscodePresented else { return }
isPasscodePresented = true
passcodeLockWindow.windowLevel = 2
let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: passcodeConfiguration)
passcodeLockVC.dismissCompletionCallback = { [weak self] in
self?.dismissPasscodeLock()
}
passcodeLockWindow.rootViewController = passcodeLockVC
}
private func dismissPasscodeLock() {
isPasscodePresented = false
mainWindow?.windowLevel = 1
mainWindow?.makeKeyAndVisible()
UIView.animateWithDuration(
0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: [.CurveEaseInOut],
animations: { [weak self] in
self?.passcodeLockWindow.alpha = 0
},
completion: { [weak self] _ in
self?.passcodeLockWindow.windowLevel = 0
self?.passcodeLockWindow.rootViewController = nil
self?.passcodeLockWindow.alpha = 1
}
)
}
}