我想调用
[[self navigationController] popViewControllerAnimated:YES]
函数,但希望动画效果从右到左滑动而不是从左到右。有什么简单的方法可以实现吗?我想返回到上一个视图。感谢任何帮助。谢谢![[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];
Swift版本:
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)
transition.type = kCATransitionPush
就足够了。 - Markus Rautopuro