Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fileprivate extension UIWindow {
- func switchRootViewController(_ viewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = .transitionFlipFromRight, completion: (() -> Void)? = nil) {
- let previousViewController = rootViewController
- UIView.transition(with: self, duration: duration, options: options, animations: {
- let oldState = UIView.areAnimationsEnabled
- UIView.setAnimationsEnabled(false)
- self.rootViewController = viewController
- UIView.setAnimationsEnabled(oldState)
- }) { _ in
- Workarounds.cleanupWindowAfterRootReplacement(window: self,
- previousViewController: previousViewController)
- completion?()
- }
- }
- }
Add Comment
Please, Sign In to add comment