1.使用UIView类函数实现:
//UIViewAnimationTransitionFlipFromLeft, 向左转动
//UIViewAnimationTransitionFlipFromRight, 向右转动
//UIViewAnimationTransitionCurlUp, 向上翻动
//UIViewAnimationTransitionCurlDown, 向下翻动
[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:0.5f]; //动画时长
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatAutoreverses:NO];//是否自动返回以前动画
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; //给视图添加过渡效果
//在这里写你的代码.
[UIView commitAnimations]; //提交动画
2.使用CATransition 公开API对象来实现:
- (IBAction)doPublicCATransition:(id)sender{
CATransition *animation = [CATransition animation];
//animation.delegate = self;
animation.duration = 0.5f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
//animation.removedOnCompletion = NO;
UIButton *theButton = (UIButton *)sender;
switch (theButton.tag) {
case 0:
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
break;
case 1:
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromTop;
break;
case 2:
animation.type = kCATransitionReveal;
animation.subtype = kCATransitionFromTop;
break;
case 3:
animation.type = kCATransitionFade;
animation.subtype = kCATransitionFromTop;
break;
default:
break;
}
[self.view.layer addAnimation:animation forKey:@"animation"];
}
3.使用CATransition 公开API对象来实现:
过渡效果
fade //交叉淡化过渡(不支持过渡方向)
push //新视图把旧视图推出去
moveIn //新视图移到旧视图上面
reveal //将旧视图移开,显示下面的新视图
cube //立方体翻滚效果
oglFlip //上下左右翻转效果
suckEffect //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl //向上翻页效果
pageUnCurl //向下翻页效果
cameraIrisHollowOpen //相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
过渡方向
fromRight;
fromLeft;
fromTop;
fromBottom;
//animation.type = @"cube"; //过度效果
//animation.subtype = @"formLeft"; //过渡方向
- (IBAction)doPrivateCATransition:(id)sender{
CATransition *animation = [CATransition animation];
animation.delegate = self;
float i = slider.value;
animation.duration = 0.5f * slider.value;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.endProgress = slider.value;
animation.removedOnCompletion = NO;
UIButton *theButton = (UIButton *)sender;
switch (theButton.tag) {
case 0:
animation.type = @"cube";//---
break;
case 1:
animation.type = @"suckEffect";//103
break;
case 2:
animation.type = @"oglFlip";//When subType is "fromLeft" or "fromRight", it's the official one.
break;
case 3:
animation.type = @"rippleEffect";//110
break;
case 4:
animation.type = @"pageCurl";//101
break;
case 5:
animation.type = @"pageUnCurl";//102
break;
case 6:
animation.type = @"cameraIrisHollowOpen ";//107
break;
case 7:
animation.type = @"cameraIrisHollowClose ";//106
break;
default:
break;
}
[self.view.layer addAnimation:animation forKey:@"animation"];
self.lastAnimation = animation;
if(slider.value == 1)
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//Just remove, not release or dealloc
else{
for (int i = 0; i < [self.view.subviews count]; i++) {
[[self.view.subviews objectAtIndex:i] setUserInteractionEnabled:NO];
}
isHalfAnimation = YES;
}
}