Swift 如何在leftBarButtonItem上的pushViewController上更改动画方向?

Swift 如何在leftBarButtonItem上的pushViewController上更改动画方向?,swift,navigation,uinavigationbar,uibarbuttonitem,swift4.2,Swift,Navigation,Uinavigationbar,Uibarbuttonitem,Swift4.2,我已将LeftBarButtonim添加到NavigationBar(与NavigationController结合使用)。leftBarButtonItem位于顶视图控制器上 当我使用pushViewController func转到下一个ViewController时,动画从右向左,与按下导航栏右侧的按钮时相同 如何更改动画方向,使其从左向右移动,例如在按导航栏上的“左”按钮时,如何更改Tinder中的动画方向 代码如下: let profileButton = UIBarButtonIte

我已将LeftBarButtonim添加到NavigationBar(与NavigationController结合使用)。leftBarButtonItem位于顶视图控制器上

当我使用pushViewController func转到下一个ViewController时,动画从右向左,与按下导航栏右侧的按钮时相同

如何更改动画方向,使其从左向右移动,例如在按导航栏上的“左”按钮时,如何更改Tinder中的动画方向

代码如下:

let profileButton = UIBarButtonItem(image: #imageLiteral(resourceName: "profile"), style: .plain, target: self, action: #selector(self.showProfile))
    self.navigationItem.leftBarButtonItem = profileButton

@objc func showProfile() {
    let profileViewController = storyboard?.instantiateViewController(withIdentifier: "profile") as! ProfileViewController
    self.navigationController?.pushViewController(profileViewController, animated: true)
}

无法更改UINavigationController的方向。 为了实现这一点,你必须自己创造它。
如果要实现菜单,可以签出。

要在推送到另一个viewController时设置动画,可以使用CATTransition

@objc func showProfile() {
    let profileViewController = storyboard?.instantiateViewController(withIdentifier: "profile") as! ProfileViewController
    let transition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
    transition.type = CATransitionType.push
    transition.subtype = CATransitionSubtype.fromLeft       
    navigationController?.view.layer.add(transition, forKey: kCATransition)
    self.navigationController?.pushViewController(profileViewController, animated: true)
}

您可以将动画方向更改为从右到右、从上到下

侧菜单提示!如果我要手动创建过渡,我将如何实现所需的动画?假设您想要一个rootViewController,另一个从右侧,另一个从左侧。总共3个视图控制器。我将使用一个
UIScrollView
并将这三个视图控制器添加到其中,调整它们的帧,使它们一个接一个地放置(y=0,x={screenWidth*positionIndex},将scrollView的
paging
属性设置为true,最后将内容大小设置为ViewController的大小。也许本教程将是一个好的开始:找到另一个可能有用的git repo。UIPageViewController将采用不同的方法