Last active
June 5, 2017 09:52
-
-
Save ucotta/fae79307b3477dd0989a5fcd746b4279 to your computer and use it in GitHub Desktop.
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
extension UIViewController { | |
func setAsRootViewController(animated: Bool, completion: (() -> Void)?) { | |
let appDelegate = UIApplication.shared.delegate as? AppDelegate | |
if animated { | |
UIView.transition(with: (appDelegate?.window)!, duration: 0.5, options: .transitionCrossDissolve, | |
animations: { | |
let oldState: Bool = UIView.areAnimationsEnabled | |
UIView.setAnimationsEnabled(false) | |
appDelegate?.window?.rootViewController = self | |
UIView.setAnimationsEnabled(oldState) | |
}, | |
completion: { (finished: Bool) -> () in completion?() }) | |
} else { | |
appDelegate?.window?.rootViewController = self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment