Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidlondono/8a4696140fafc8d8522df497737fe80a to your computer and use it in GitHub Desktop.
Save davidlondono/8a4696140fafc8d8522df497737fe80a to your computer and use it in GitHub Desktop.
Switch root view controller
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)? = nil) {
guard let window = window else { return }
if animated {
UIView.transitionWithView(window, duration: 0.5, options: .TransitionCrossDissolve, animations: {
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
window.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
completion?()
})
} else {
window.rootViewController = rootViewController
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment