I am setting a new navigation root. I want to show the animation when navigation is set. I am able to set the flip & curl animation with below code.
UIView.transition(with: self.window!, duration: 2, options: .transitionFlipFromLeft, animations: {
let navController = UINavigationController()
// App Theming
navController.navigationBar.barTintColor = .white
navController.navigationBar.tintColor = .white
navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
navController.pushViewController(viewContoller, animated: true)
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
}, completion: {_ in})
But, I need to set a slide animation from left to right for this. Can any body let me know how can I achieve this?
If you want to fake a push on a new root view you could do something like this.
let navController = UINavigationController()
//App Theming
navController.navigationBar.barTintColor = .white
navController.navigationBar.tintColor = .white
navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
//create our fake animation
let trans = CATransition()
trans.type = kCATransitionPush
trans.subtype = kCATransitionFromRight
trans.duration = 0.4
self.window?.layer.add(trans, forKey: nil)
//set your window change here
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
Completely untested but I am pretty sure I have done this in the past at some point. If that does not work try setting the rootViewController then adding the animation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.