简体   繁体   English

如何在Swift 4中从左到右更改导航动画?

[英]how to change navigation animation to left to right in swift 4?

I have a navigation bar in my application that I change the navigation to present modally But I want when user goes to the destination view controller the navigation animation from left to right 我的应用程序中有一个导航栏,可以将导航更改为模态显示,但是我希望当用户转到目标视图控制器时,导航动画从左到右

here is my codes in the first view controller 这是我在第一个视图控制器中的代码

    @IBAction func showProfilePage(_ sender: UIBarButtonItem) {


    self.performSegue(withIdentifier: "showprofile", sender: self)


}

I read apple site for this and use this function too 我为此阅读了苹果网站,也使用了此功能

private func navigationController(_ navigationController: UINavigationController,
                                   willShow viewController: ProfileViewController,
                                   animated: Bool) {




}

But it doesn't work so what should I do to change navigation animation from left to right? 但这不起作用,所以我应该怎么做才能从左到右更改导航动画?

Try this. 尝试这个。

let storyBoard : UIStoryboard = UIStoryboard(name: "PatientCheckout", bundle:nil)
let controller = storyBoard.instantiateViewController(withIdentifier: "PatientCheckoutViewController") as UIViewController

let transition = CATransition.init()
transition.duration = 0.45
transition.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionDefault)
transition.type = kCATransitionPush //Transition you want like Push, Reveal
transition.subtype = kCATransitionFromLeft // Direction like Left to Right, Right to Left
transition.delegate = self
view.window!.layer.add(transition, forKey: kCATransition)
self.navigationController?.pushViewController(controller, animated: true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM