Created
June 1, 2018 11:00
-
-
Save ahbou/ba5a3ea3de28a411c185085ac48fdda5 to your computer and use it in GitHub Desktop.
Animate UIWindow rootViewController switch
This file contains hidden or 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
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