From ec10a2857cd21e1554ea6461c00f8fc79a382735 Mon Sep 17 00:00:00 2001 From: Andrey Panchenko Date: Sat, 18 Jun 2016 22:41:47 +0300 Subject: [PATCH] Configurable window levels. --- PasscodeLock/PasscodeLockPresenter.swift | 14 ++++++++------ .../PasscodeLockConfigurationType.swift | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/PasscodeLock/PasscodeLockPresenter.swift b/PasscodeLock/PasscodeLockPresenter.swift index 7f1f619d..f76dade6 100644 --- a/PasscodeLock/PasscodeLockPresenter.swift +++ b/PasscodeLock/PasscodeLockPresenter.swift @@ -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 @@ -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 @@ -64,7 +64,7 @@ public class PasscodeLockPresenter { guard !isPasscodePresented else { return } isPasscodePresented = true - passcodeLockWindow.windowLevel = 2 + passcodeLockWindow.windowLevel = passcodeConfiguration.passcodeFrontWindowLevel toggleKeyboardVisibility(hide: true) @@ -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, @@ -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) } diff --git a/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift b/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift index ec158e75..d754748f 100644 --- a/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift +++ b/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift @@ -7,6 +7,7 @@ // import Foundation +import CoreGraphics public protocol PasscodeLockConfigurationType { @@ -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 + } +} \ No newline at end of file