我正在尝试调用
[[self navigationController] popViewControllerAnimated:YES]
但使动画从右向左滑动而不是从左向右滑动。有什么简单的方法可以做到这一点吗?我想回到之前的观点。任何帮助表示赞赏。谢谢!
这就是如何在相反方向弹出视图控制器。它对我来说 100% 有效
CATransition *transition = [CATransition animation];
transition.duration = 0.45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionFromRight;
[transition setType:kCATransitionPush];
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
这是可能的,看看我不久前使用的以下代码,并尝试让它为自己工作。你只需要改变
setAnimationTransition
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
有几种不同类型的默认动画可供使用,苹果网站说这种动画是可能的:
typedef enum {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;
因此,在您的情况下,您需要使用以下内容:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController popViewControllerAnimated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
快速版本:
let animation = CATransition()
animation.duration = 0.3
animation.type = .push
animation.subtype = .fromRight
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
navigationController?.view.layer.add(animation, forKey: nil)
navigationController?.popViewController(animated: false)