Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable window levels. #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions PasscodeLock/PasscodeLockPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PasscodeLockPresenter {

let window = UIWindow(frame: UIScreen.mainScreen().bounds)

window.windowLevel = 0
window.windowLevel = self.passcodeConfiguration.passcodeBackWindowLevel
window.makeKeyAndVisible()

return window
Expand All @@ -30,7 +30,7 @@ public class PasscodeLockPresenter {
public init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, viewController: PasscodeLockViewController) {

mainWindow = window
mainWindow?.windowLevel = 1
mainWindow?.windowLevel = configuration.mainWindowLevel
passcodeConfiguration = configuration

passcodeLockVC = viewController
Expand Down Expand Up @@ -64,7 +64,7 @@ public class PasscodeLockPresenter {
guard !isPasscodePresented else { return }

isPasscodePresented = true
passcodeLockWindow.windowLevel = 2
passcodeLockWindow.windowLevel = passcodeConfiguration.passcodeFrontWindowLevel

toggleKeyboardVisibility(hide: true)

Expand All @@ -83,9 +83,11 @@ public class PasscodeLockPresenter {
public func dismissPasscodeLock(animated animated: Bool = true) {

isPasscodePresented = false
mainWindow?.windowLevel = 1
mainWindow?.windowLevel = passcodeConfiguration.mainWindowLevel
mainWindow?.makeKeyAndVisible()

let passcodeBackWindowLevel = passcodeConfiguration.passcodeBackWindowLevel

if animated {
UIView.animateWithDuration(
0.5,
Expand All @@ -99,14 +101,14 @@ public class PasscodeLockPresenter {
},
completion: { [weak self] _ in

self?.passcodeLockWindow.windowLevel = 0
self?.passcodeLockWindow.windowLevel = passcodeBackWindowLevel
self?.passcodeLockWindow.rootViewController = nil
self?.passcodeLockWindow.alpha = 1
self?.toggleKeyboardVisibility(hide: false)
}
)
} else {
passcodeLockWindow.windowLevel = 0
passcodeLockWindow.windowLevel = passcodeBackWindowLevel
passcodeLockWindow.rootViewController = nil
toggleKeyboardVisibility(hide: false)
}
Expand Down
19 changes: 19 additions & 0 deletions PasscodeLock/Protocols/PasscodeLockConfigurationType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import CoreGraphics

public protocol PasscodeLockConfigurationType {

Expand All @@ -16,4 +17,22 @@ public protocol PasscodeLockConfigurationType {
var shouldRequestTouchIDImmediately: Bool {get}
var touchIdReason: String? {get set}
var maximumInccorectPasscodeAttempts: Int {get}
var mainWindowLevel: CGFloat { get }
var passcodeBackWindowLevel: CGFloat { get }
var passcodeFrontWindowLevel: CGFloat { get }
}

public extension PasscodeLockConfigurationType {

var mainWindowLevel: CGFloat {
return 1
}

var passcodeBackWindowLevel: CGFloat {
return 0
}

var passcodeFrontWindowLevel: CGFloat {
return 2
}
}