转载,来自:http://www.cnblogs.com/ubersexual/archive/2013/03/26/2983420.html
方法一:
利用iOS提供的4种视图转换类型:
- UIViewAnimationTransitionFlipFromLeft
- UIViewAnimationTransitionFlipFromRight
- UIViewAnimationTransitionCurlUp
- UIViewAnimationTransitionCurlDown
1 2 3 4 5 6 7 8 9 | 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]; |
方法二:
自定义动画:
- 在frameworks中添加QuartzCore.framework
- 在.m文件中导入 #import <QuartzCore/QuartzCore.h>
1 2 3 4 5 6 7 8 9 10 11 12 | 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]; |
实际上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”