更改navigationController push和pop界面切换动画
http://blog.csdn.net/longlongago2000/article/details/7589706
作者:longlongago 博客:http://blog.csdn.net/longlongago2000 转帖请保留
有时候我们需要自定义navigationController push和pop界面切换动画,用到的代码如下:
For Push:
- MainView *nextView=[[MainView alloc] init];
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.75];
- [self.navigationController pushViewController:nextView animated:NO];
- [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
- [UIView commitAnimations];
- [nextView release];
For Pop:
方法一:
- [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];
方法二:
可实现左右滑动动画,可设置滑动方向。
- CATransition* transition = [CATransition animation];
- transition.duration = 0.5;
- transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
- //transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
- [self.navigationController.view.layer addAnimation:transition forKey:nil];
- [[self navigationController] popViewControllerAnimated:NO];
具体的动画参数请自行更改。
- 上一篇[转]loadView/viewDidLoad/initWithNibName/awakeFromNib/initWithCoder的用法
-
-
CATransition *animation = [CATransition animation];
animation.duration = 0.6;
animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
animation.type = @"cube";
animation.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:animation forKey:@"test"];
UIViewController *viewCtrl = [[UIViewController alloc] init];
[self.navigationController pushViewController:viewCtrl animated:NO];
-
-