Skip to content

Instantly share code, notes, and snippets.

@ucotta
Last active June 5, 2017 09:52
Show Gist options
  • Save ucotta/fae79307b3477dd0989a5fcd746b4279 to your computer and use it in GitHub Desktop.
Save ucotta/fae79307b3477dd0989a5fcd746b4279 to your computer and use it in GitHub Desktop.
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