Skip to content

Instantly share code, notes, and snippets.

@starhoshi
Created June 27, 2017 12:30
Show Gist options
  • Save starhoshi/4de7244849d1e3f9b1dd29ccc60c56af to your computer and use it in GitHub Desktop.
Save starhoshi/4de7244849d1e3f9b1dd29ccc60c56af to your computer and use it in GitHub Desktop.
rootViewController を別の ViewController に入れ替える [Swift3]
import UIKit
extension UIWindow {
func changeRootViewController(new viewController: UIViewController) {
UIView.transition(
with: UIApplication.shared.keyWindow!,
duration: 0.5,
options: .transitionCrossDissolve,
animations: {
UIApplication.shared.keyWindow?.rootViewController = viewController
},
completion: nil
)
}
}
UIWindow().changeRootViewController(new: UIViewController())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment