使用UIView类的UIViewAnimation扩展
UIView动画是成块运行的。发出beginAnimations:context:请求标志着动画块的开始;commitAnimations标志着动画块的结束。把这两个类方法发送给UIView而不是发送给单独的视图。在这两个调用之间的可定义动画的展现方式并更新视图。函数说明:
//开始准备动画
+ (void)beginAnimations:(NSString *)animationID context:(void *)context;
//运行动画
+ (void)commitAnimations;
具体二段动画代码:
[UIView beginAnimations:nil context:nil];
//setAnimationCurve来定义动画加速或减速方式
[UIView setAnimaitonCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:2.7]; //动画时长
[UIView setAnimationTransition:transition forView:self.view cache:YES];
// operation>>>
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
// end<<<<<
[UIView commitAnimations];
CGContextRef context = UIGraphicsGetCurrentContext(); //返回当前视图堆栈顶部的图形上下文
[UIView beginAnimations:nil context:context];
[UIView setAnimaitonCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
// View changes go here
[contextView setAlpha:0.0f];
[UIView commitAnimations];
其中transition取值范围:UIView类本身提供四种过渡效果
UIViewAnimationTransitionNone 正常
UIViewAnimationTransitionFlipFromLeft 从左向右翻
UIViewAnimationTransitionFlipFromRight 从右向左翻
UIViewAnimationTransitionCurlUp 从下向上卷
UIViewAnimationTransitionCurlDown 从上向下卷