我查看了一下,没有找到我需要的内容。
在推送视图控制器时,有没有一种方法可以获得翻转动画?
我读到可以通过使用模态视图控制器来更改动画,但是据我所知,模态视图的动画是从底部到顶部,这不是我想要的。有没有办法以某种方式获取翻转动画?
这样应该可以工作
[UIView beginAnimations:@"animation" context:nil];
[self.navigationController pushViewController: yourviewcontroller animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
调用pushViewController时,别忘了将animated设置为NO。
这也适用于 iOS 4.0 及更高版本
[UIView transitionWithView:self.navigationController.view duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
- (void)viewWillDisappear:(BOOL)animated {
[UIView beginAnimations:@"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations]; }
在新的视图控制器中,当工具栏中的“返回”按钮被按下时,它将以相同的方式翻转回去(而不是向左滑动)。请确保启用动画效果,例如,如果您想使用自定义按钮弹出堆栈,请使用以下代码:
- (void) backToPrevious: (id) sender
{
//[self.navigationController popViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
}
beginAnimations:context:
方法是苹果公司不建议开发者使用的一组方法(从iOS 4开始)。他们推荐使用UIView的基于块的动画方法(例如,animateWithDuration:animations:completion:
)代替。 - user577537对于以模式呈现的视图控制器,您可以使用modalTransitionStyle
属性更改动画。据我所知,没有办法更改导航控制器的推送动画(除非从头开始重建UINavigationController)。
animated:NO
是很重要的。谢谢你提到它。 - abc123