diff --git a/PasscodeLock/Functions.swift b/PasscodeLock/Functions.swift index adb03903..df0b56bb 100644 --- a/PasscodeLock/Functions.swift +++ b/PasscodeLock/Functions.swift @@ -11,9 +11,9 @@ import Foundation func localizedStringFor(key: String, comment: String) -> String { let name = "PasscodeLock" - let bundle = bundleForResource(name, ofType: "strings") + let defaultString = NSLocalizedString(key, tableName: name, bundle: NSBundle(forClass: PasscodeLock.self), comment: comment) - return NSLocalizedString(key, tableName: name, bundle: bundle, comment: comment) + return NSLocalizedString(key, value: defaultString, tableName: name, bundle: NSBundle.mainBundle(), comment: comment) } func bundleForResource(name: String, ofType type: String) -> NSBundle { diff --git a/PasscodeLock/PasscodeLockPresenter.swift b/PasscodeLock/PasscodeLockPresenter.swift index 7f1f619d..66de59f6 100644 --- a/PasscodeLock/PasscodeLockPresenter.swift +++ b/PasscodeLock/PasscodeLockPresenter.swift @@ -87,28 +87,34 @@ public class PasscodeLockPresenter { mainWindow?.makeKeyAndVisible() if animated { - 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 - self?.toggleKeyboardVisibility(hide: false) - } - ) + + animatePasscodeLockDismissal() + } else { passcodeLockWindow.windowLevel = 0 passcodeLockWindow.rootViewController = nil toggleKeyboardVisibility(hide: false) } } + + internal func animatePasscodeLockDismissal() { + 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 + self?.toggleKeyboardVisibility(hide: false) + } + ) + } } diff --git a/PasscodeLock/PasscodeLockViewController.swift b/PasscodeLock/PasscodeLockViewController.swift index 6fb0887f..8b912aa2 100644 --- a/PasscodeLock/PasscodeLockViewController.swift +++ b/PasscodeLock/PasscodeLockViewController.swift @@ -82,6 +82,8 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg public override func viewDidLoad() { super.viewDidLoad() + cancelButton?.setTitle(localizedStringFor("PasscodeLockCancelButtonTitle", comment: "Cancel Button Title"), forState: .Normal) + deleteSignButton?.setTitle(localizedStringFor("PasscodeLockDeleteButtonTitle", comment: "Delete Button Title"), forState: .Normal) deleteSignButton?.enabled = false setupEvents() @@ -114,8 +116,8 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg private func setupEvents() { - notificationCenter?.addObserver(self, selector: "appWillEnterForegroundHandler:", name: UIApplicationWillEnterForegroundNotification, object: nil) - notificationCenter?.addObserver(self, selector: "appDidEnterBackgroundHandler:", name: UIApplicationDidEnterBackgroundNotification, object: nil) + notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appWillEnterForegroundHandler(_:)), name: UIApplicationWillEnterForegroundNotification, object: nil) + notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appDidEnterBackgroundHandler(_:)), name: UIApplicationDidEnterBackgroundNotification, object: nil) } private func clearEvents() { diff --git a/PasscodeLock/Views/PasscodeSignButton.swift b/PasscodeLock/Views/PasscodeSignButton.swift index 9fb3968a..dfd9fe0c 100644 --- a/PasscodeLock/Views/PasscodeSignButton.swift +++ b/PasscodeLock/Views/PasscodeSignButton.swift @@ -55,7 +55,7 @@ public class PasscodeSignButton: UIButton { return CGSizeMake(60, 60) } - private var defaultBackgroundColor = UIColor.clearColor() + public var defaultBackgroundColor = UIColor.clearColor() private func setupView() { @@ -71,8 +71,8 @@ public class PasscodeSignButton: UIButton { private func setupActions() { - addTarget(self, action: Selector("handleTouchDown"), forControlEvents: .TouchDown) - addTarget(self, action: Selector("handleTouchUp"), forControlEvents: [.TouchUpInside, .TouchDragOutside, .TouchCancel]) + addTarget(self, action: #selector(PasscodeSignButton.handleTouchDown), forControlEvents: .TouchDown) + addTarget(self, action: #selector(PasscodeSignButton.handleTouchUp), forControlEvents: [.TouchUpInside, .TouchDragOutside, .TouchCancel]) } func handleTouchDown() { diff --git a/PasscodeLock/en.lproj/PasscodeLock.strings b/PasscodeLock/en.lproj/PasscodeLock.strings index f71ef86c..8ae4e796 100755 --- a/PasscodeLock/en.lproj/PasscodeLock.strings +++ b/PasscodeLock/en.lproj/PasscodeLock.strings @@ -26,6 +26,12 @@ "PasscodeLockMismatchTitle" = "Try again"; "PasscodeLockMismatchDescription" = "Passcodes didn\'t match."; +/* Cancel Button Title */ +"PasscodeLockCancelButtonTitle" = "Cancel"; + +/* Delete Button Title */ +"PasscodeLockDeleteButtonTitle" = "Delete"; + /* Touch ID Reason */ "PasscodeLockTouchIDReason" = "Authentication required to proceed"; diff --git a/PasscodeLockDemo/PasscodeSettingsViewController.swift b/PasscodeLockDemo/PasscodeSettingsViewController.swift index 36ac6123..434b0197 100644 --- a/PasscodeLockDemo/PasscodeSettingsViewController.swift +++ b/PasscodeLockDemo/PasscodeSettingsViewController.swift @@ -64,7 +64,8 @@ class PasscodeSettingsViewController: UIViewController { passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration) passcodeVC.successCallback = { lock in - + self.passcodeSwitch.on = !self.passcodeSwitch.on + self.changePasscodeButton.hidden = true lock.repository.deletePasscode() } } diff --git a/README.md b/README.md index 410cb589..e1143469 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,9 @@ Also you can set the initial passcode lock state to your own implementation of t ### Custom Design -The PasscodeLock will look for `PasscodeLockView.xib` inside your app bundle and if it can't find it will load its default one, so if you want to have a custom design create a new `xib` with the name `PasscodeLockView` and set its owner to an instance of `PasscodeLockViewController` class. +The PasscodeLock will look for `PasscodeLockView.xib` inside your app bundle and if it can't find it will load its default one, so if you want to have a custom design create a new `xib` with the name `PasscodeLockView` and set its owner to an instance of `PasscodeLockViewController` class and module to `PasscodeLock`. -Then connect the `view` outlet to the view of your `xib` file and make sure to conenct the remaining `IBOutlet`s and `IBAction`s. +Then connect the `view` outlet to the view of your `xib` file and make sure to connect the remaining `IBOutlet`s and `IBAction`s. Also make sure to set module to `PasscodeLock` on all `PasscodeSignPlaceholderView` and `PasscodeSignButton` in the nib. PasscodeLock comes with two view components: `PasscodeSignPlaceholderView` and `PasscodeSignButton` that you can use to create your own custom designs. Both classes are `@IBDesignable` and `@IBInspectable`, so you can see their appearance and change their properties right inside the interface builder: