Guest User

Untitled

a guest
Dec 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. fileprivate extension UIWindow {
  2.  
  3. func switchRootViewController(_ viewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = .transitionFlipFromRight, completion: (() -> Void)? = nil) {
  4.  
  5. let previousViewController = rootViewController
  6.  
  7. UIView.transition(with: self, duration: duration, options: options, animations: {
  8. let oldState = UIView.areAnimationsEnabled
  9. UIView.setAnimationsEnabled(false)
  10. self.rootViewController = viewController
  11. UIView.setAnimationsEnabled(oldState)
  12.  
  13. }) { _ in
  14. Workarounds.cleanupWindowAfterRootReplacement(window: self,
  15. previousViewController: previousViewController)
  16.  
  17. completion?()
  18. }
  19.  
  20. }
  21.  
  22. }
Add Comment
Please, Sign In to add comment