Created
August 25, 2015 01:52
-
-
Save tempire/e6f1a2831f5688d352da to your computer and use it in GitHub Desktop.
present view controller on entering background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func frontViewController(window: UIWindow) -> UIViewController { | |
if let rootVC = window.rootViewController { | |
var frontVC = rootVC | |
while (true) { | |
if let vc = frontVC.presentedViewController { frontVC = vc } | |
else { break } | |
} | |
return frontVC | |
} | |
return window.rootViewController! | |
} | |
func applicationDidEnterBackground(application: UIApplication) { | |
if let window = application.windows[0] as? UIWindow, | |
let model = self.model, | |
let vc = storyboard.instantiateViewControllerWithIdentifier("LoginWithStoredAuthVC") as? LoginWithStoredAuthVC { | |
window.rootViewController?.view.endEditing(true) | |
let frontVC = self.frontViewController(window) | |
if frontVC is LoginWithStoredAuthVC || frontVC is LoginWithUserAndPassVC { return } | |
vc.model = model | |
vc.modalTransitionStyle = UIModalTransitionStyle.CoverVertical | |
vc.modalPresentationStyle = UIModalPresentationStyle.FullScreen | |
frontVC.presentViewController(vc, animated: false, completion: nil) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment