-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UIWindow extension to switch the rootViewController with animation #477
Comments
Hi @omaralbeik , i have following implementation regarding this issue public func switchRootVC(to viewController: UIViewController, duration: TimeInterval, completion: @escaping () -> Void) {
viewController.view.alpha = 0.0
viewController.view.frame = CGRect.init(x: 0, y: frame.size.height, width: frame.size.width, height: frame.size.height)
addSubview(viewController.view)
UIView.animate(withDuration: duration, animations: {
viewController.view.alpha = 1.0
viewController.view.frame = self.frame
}) { (_) in
self.rootViewController = viewController
completion()
}
} with It will restrict the developer to the animation provided in the Please share your thought. |
Nice job @ratulSharker, thanks for adding the screenshot as well 💯, my only comment is we want to give users more options to choose other animations. I'm using the following implementaion, it uses public extension UIWindow {
/// Switch current root view controller with a new view controller.
///
/// - Parameters:
/// - viewController: new view controller.
/// - animated: set to true to animate view controller change _(default is true)_.
/// - duration: animation duration in seconds _(default is 0.5)_.
/// - options: animataion options _(default is .transitionFlipFromRight)_.
/// - completion: optional completion handler called when view controller is changed.
public func switchRootViewController(to viewController: UIViewController, animated: Bool = true, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = .transitionFlipFromRight, _ completion: (() -> Void)? = nil) {
guard animated else {
rootViewController = viewController
return
}
UIView.transition(with: self, duration: duration, options: options, animations: {
let oldState = UIView.areAnimationsEnabled
UIView.setAnimationsEnabled(false)
self.rootViewController = viewController
UIView.setAnimationsEnabled(oldState)
}, completion: { _ in
completion?()
})
}
} |
Any iOS 13 implementation for the same ? This gives me blank screen in iOS 13 |
I tested it in iOS 13.5 in simulator. It is working well. |
Add an extension to change
rootViewController
in aUIWindow
with animation, duration, UIViewAnimationOptions and a completion handler.The text was updated successfully, but these errors were encountered: