Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zhaozzq/aa96271e7062c9305ca76903d0db9478 to your computer and use it in GitHub Desktop.
Save zhaozzq/aa96271e7062c9305ca76903d0db9478 to your computer and use it in GitHub Desktop.
Switch root view controller
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
if animated {
UIView.transitionWithView(window, duration: 0.5, options: .TransitionCrossDissolve, animations: {
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
self.window!.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
if completion {
completion!()
}
})
} else {
window!.rootViewController = rootViewController
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment