Skip to content

Instantly share code, notes, and snippets.

@ahbou
Created June 1, 2018 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahbou/ba5a3ea3de28a411c185085ac48fdda5 to your computer and use it in GitHub Desktop.
Save ahbou/ba5a3ea3de28a411c185085ac48fdda5 to your computer and use it in GitHub Desktop.
Animate UIWindow rootViewController switch
extension UIWindow {
func setRootViewController(_ rootViewController: UIViewController?, animated: Bool) {
guard let viewContoller = rootViewController else {
self.rootViewController = rootViewController
return
}
var snapShotView: UIView?
if (animated) {
if let snapShot = snapshotView(afterScreenUpdates: true) {
snapShotView = snapShot
viewContoller.view.addSubview(snapShot)
}
}
self.rootViewController = viewContoller
if (animated) {
UIView.animate(withDuration: 0.25, animations: {
snapShotView?.layer.opacity = 0
snapShotView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
}) { (_) in
snapShotView?.removeFromSuperview()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment