-
-
Save susieyy/5146868cc71d97ebaa2cb725ee13637e to your computer and use it in GitHub Desktop.
#swtws
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
guard let window = UIApplication.sharedApplication().appDelegate.window, rootViewController = window.rootViewController else { return } | |
let newRootViewController = UINavigationController(rootViewController: vc) | |
// rootViewControllerを差し替える場合は、メモリリーク防止のため事前にdismissを行います | |
// https://gist.github.com/mono0926/abd7d079361f36efdd9068b27b41ea50 | |
UIView.transitionWithView(window, duration: 0.2, options: .CurveEaseInOut, animations: { | |
rootViewController.dismissdismissViewControllerAnimated(false, completion: nil) | |
window.rootViewController = newRootViewController | |
}) { _ in } | |
// rootViewControllerを差し替えず、ChildViewControllerの差し替えで行う方法もあります | |
// refs. http://dealforest.hatenablog.com/entry/2016/12/14/124555 | |
UIView.transitionWithView(window, duration: 0.2, options: .CurveEaseInOut, animations: { | |
rootViewController.childViewControllers.forEach { | |
$0.view.removeFromSuperview() | |
$0.removeFromParentViewController() | |
} | |
rootViewController.view.addSubView(newRootViewController.view) | |
rootViewController.addChildViewController(newRootViewController) | |
newRootViewController.didMoveToParentViewController(rootViewController) | |
}) { _ in } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment