[英]Slide animation with UIView Transition?
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.
如果这样不起作用,请尝试设置rootViewController,然后添加动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.