方法一:
利用iOS提供的4种视图转换类型:
- UIViewAnimationTransitionFlipFromLeft
- UIViewAnimationTransitionFlipFromRight
- UIViewAnimationTransitionCurlUp
- UIViewAnimationTransitionCurlDown
1 MainView *nextView=[[MainView alloc] init]; 2 [UIView beginAnimations:nil context:NULL]; 3 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 4 [UIView setAnimationDuration:0.75]; 5 [self.navigationController pushViewController:nextView animated:NO]; 6 //选择动画 7 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; 8 [UIView commitAnimations]; 9 [nextView release];
方法二:
自定义动画:
- 在frameworks中添加QuartzCore.framework
- 在.m文件中导入 #import <QuartzCore/QuartzCore.h>
1 CATransition* transition = [CATransition animation]; 2 //执行时间长短 3 transition.duration = 0.5; 4 //动画的开始与结束的快慢 5 transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 6 //各种动画效果 7 transition.type = kCATransitionFade; //kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade 8 //动画方向 9 //transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom 10 //将动画添加在视图层上 11 [self.navigationController.view.layer addAnimation:transition forKey:nil]; 12 [[self navigationController] popViewControllerAnimated:NO];
实际上CATransition类中还有一个属性是removedOnCompletion,是此动画执行完后会自动remove,默认值为true。
transition的type可以返回四种类型:
- kCATransitionFade 淡出
- kCATransitionMoveIn 覆盖原图
- kCATransitionPush 推出
- kCATransitionReveal 底部显出来
transition的subtype也可以有四种类型:
- kCATransitionFromRight
- kCATransitionFromLeft (默认值)
- kCATransitionFromTop
- kCATransitionFromBottom
还有一种设置动画类型的方法,不用setSubtype,只用setType
[transition setType:@"suckEffect"]; 或者 transition.type = @"suckEffect";
这里的suckEffect为效果名,主要效果有:
- pageCurl 向上翻一页
- pageUnCurl 向下翻一页
- rippleEffect 滴水效果
- suckEffect 收缩效果,如一块布被抽走
- cube 立方体效果
- oglFlip 上下翻转效果
//@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"