UIViewAnimation动画与Core Animation的CATransition类动画

 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;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值