UIViewAnimation与Core Animation的CATransition类

Java代码 
  1. @interface CAAnimation : NSObject <NSCoding, NSCopying, CAMediaTiming, CAAction>  
  2.   
  3. CATransition类:  
  4. @interface CATransition : CAAnimation  
  5.   
  6. CAPropertyAnimation类:  
  7. @interface CAPropertyAnimation : CAAnimation  
  8.   
  9. CABasicAnimation类:  
  10. @interface CABasicAnimation : CAPropertyAnimation  
  11.   
  12. CAKeyframeAnimation类:  
  13. @interface CAKeyframeAnimation : CAPropertyAnimation  
  14.   
  15. 通过layer方法:  
  16. [imageView.layer addAnimation:animation forKey:nil];将动画添加到图层  
  17.   
  18. 还可以设置layer的属性:(3D变幻)  
  19. @property CATransform3D transform;  
  20.   
  21. 还可以设置affineTransform:(平面变化)  
  22. - (CGAffineTransform)affineTransform;  
  23. - (void)setAffineTransform:(CGAffineTransform)m;  





1.CATransition类 

关键代码: 
Java代码 
  1. - (void)leftClick {   
  2.   
  3.     [UIView beginAnimations:nil context:nil];  
  4.     //display mode, slow at beginning and end  
  5.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  6.     //动画时间  
  7.     [UIView setAnimationDuration:1.0f];  
  8.     //使用当前正在运行的状态开始下一段动画  
  9.     [UIView setAnimationBeginsFromCurrentState:YES];  
  10.     //给视图添加过渡效果  
  11.     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imageView cache:YES];  
  12.     [UIView commitAnimations];  
  13. }  
  14.   
  15. - (void)rightClick {  
  16.       
  17.     [UIView beginAnimations:nil context:nil];  
  18.     //display mode, slow at beginning and end  
  19.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  20.     //动画时间  
  21.     [UIView setAnimationDuration:1.0f];  
  22.     //使用当前正在运行的状态开始下一段动画  
  23.     [UIView setAnimationBeginsFromCurrentState:YES];  
  24.     //给视图添加过渡效果  
  25.     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:imageView cache:YES];  
  26.     [UIView commitAnimations];  
  27.       
  28. }  
  29.   
  30. - (void)upClick {   
  31.       
  32.     [UIView beginAnimations:nil context:nil];  
  33.     //display mode, slow at beginning and end  
  34.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  35.     //动画时间  
  36.     [UIView setAnimationDuration:1.0f];  
  37.     //使用当前正在运行的状态开始下一段动画  
  38.     [UIView setAnimationBeginsFromCurrentState:YES];  
  39.     //给视图添加过渡效果  
  40.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:imageView cache:YES];  
  41.     [UIView commitAnimations];  
  42. }  
  43. - (void)downClick {   
  44.       
  45.     [UIView beginAnimations:nil context:nil];  
  46.     //display mode, slow at beginning and end  
  47.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  48.     //动画时间  
  49.     [UIView setAnimationDuration:1.0f];  
  50.     //使用当前正在运行的状态开始下一段动画  
  51.     [UIView setAnimationBeginsFromCurrentState:YES];  
  52.     //给视图添加过渡效果  
  53.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:imageView cache:YES];  
  54.     [UIView commitAnimations];  
  55. }  
  56.   
  57. /*    
  58.  CATransition的type属性 
  59.   
  60.  1.#define定义的常量 
  61.      kCATransitionFade   交叉淡化过渡 
  62.      kCATransitionMoveIn 新视图移到旧视图上面 
  63.      kCATransitionPush   新视图把旧视图推出去 
  64.      kCATransitionReveal 将旧视图移开,显示下面的新视图 
  65.   
  66.  2.用字符串表示 
  67.      pageCurl            向上翻一页 
  68.      pageUnCurl          向下翻一页 
  69.      rippleEffect        滴水效果 
  70.      suckEffect          收缩效果,如一块布被抽走 
  71.      cube                立方体效果 
  72.      oglFlip             上下翻转效果   
  73. */  
  74. - (void)MyCAnimation1 {   
  75.       
  76.     CATransition *animation = [CATransition animation];  
  77.     //动画时间  
  78.     animation.duration = 1.0f;  
  79.     //display mode, slow at beginning and end  
  80.     animation.timingFunction = UIViewAnimationCurveEaseInOut;  
  81.     //过渡效果  
  82.     animation.type = kCATransitionMoveIn;  
  83.     //过渡方向  
  84.     animation.subtype = kCATransitionFromTop;  
  85.     //添加动画  
  86.     [imageView.layer addAnimation:animation forKey:nil];  
  87. }  
  88.   
  89. - (void)MyCAnimation2 {   
  90.       
  91.     CATransition *animation = [CATransition animation];  
  92.     //动画时间  
  93.     animation.duration = 1.0f;  
  94.     //display mode, slow at beginning and end  
  95.     animation.timingFunction = UIViewAnimationCurveEaseInOut;  
  96.     //在动画执行完时是否被移除  
  97.     animation.removedOnCompletion = NO;  
  98.     //过渡效果  
  99.     animation.type = @"pageCurl";  
  100.     //过渡方向  
  101.     animation.subtype = kCATransitionFromRight;  
  102.     //暂时不知,感觉与Progress一起用的,如果不加,Progress好像没有效果  
  103.     animation.fillMode = kCAFillModeForwards;  
  104.     //动画停止(在整体动画的百分比).  
  105.     animation.endProgress = 0.7;  
  106.     [imageView.layer addAnimation:animation forKey:nil];  
  107. }  
  108.   
  109. - (void)MyCAnimation3 {   
  110.       
  111.     CATransition *animation = [CATransition animation];  
  112.     //动画时间  
  113.     animation.duration = 1.0f;  
  114.     //display mode, slow at beginning and end  
  115.     animation.timingFunction = UIViewAnimationCurveEaseInOut;  
  116.     //过渡效果  
  117.     animation.type = @"pageUnCurl";  
  118.     //过渡方向  
  119.     animation.subtype = kCATransitionFromRight;  
  120.     //暂时不知,感觉与Progress一起用的,如果不加,Progress好像没有效果  
  121.     animation.fillMode = kCAFillModeBackwards;  
  122.     //动画开始(在整体动画的百分比).  
  123.     animation.startProgress = 0.3;  
  124.     [imageView.layer addAnimation:animation forKey:nil];  
  125. }  
  126.   
  127. - (void)MyCAnimation4 {   
  128.       
  129.     [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(updateButterfly) userInfo:nil repeats:YES];  
  130. }  
  131.   
  132. - (void)updateButterfly {  
  133.   
  134.     butterflyView.animationDuration = 0.75f;  
  135.     [self.view addSubview:butterflyView];  
  136.     [butterflyView startAnimating];  
  137.     butterflyView.center = [butterflyView randomCenterInView:self.view withInset:10.0f];  
  138.   
  139. }  



    #import<Foundation/Foundation.h>


    externNSString * const MyAnimationTypeToTop;

    externNSString * const MyAnimationTypeToBottom;

    externNSString * const MyAnimationTypeToRight;

    externNSString * const MyAnimationTypeToLeft;


    @interface UIView (MyAnimation)


        - (void) setHidden:(BOOL)hidden animation:(NSString*)animationType;


    @end





    #import"MyAnimations.h"

    #include<QuartzCore/CoreAnimation.h>

    NSString *const MyAnimationTypeToTop=@"MyAnimationTypeToTop";

    NSString *const MyAnimationTypeToBottom=@"MyAnimationTypeToBottom";

    NSString *const MyAnimationTypeToRight=@"MyAnimationTypeToRight";

    NSString *const MyAnimationTypeToLeft=@"MyAnimationTypeToLeft";


    @implementation UIView (MyAnimation)


    - (void) setHidden:(BOOL)hidden animation:(NSString*)animationType {

        

       CATransition *animation = [CATransitionanimation];

        [animation setDelegate:self];

        [animation setType:kCATransitionPush];

        

        if ([animationType isEqualToString:MyAnimationTypeToTop]) {

            

            [animation setSubtype:kCATransitionFromTop];


        }elseif([animationType isEqualToString:MyAnimationTypeToBottom]){

            

            [animationsetSubtype:kCATransitionFromBottom];

            

        }elseif([animationType isEqualToString:MyAnimationTypeToLeft]){

            

            [animation setSubtype:kCATransitionFromRight];

            

        }elseif([animationType isEqualToString:MyAnimationTypeToRight]){

            

            [animation setSubtype:kCATransitionFromLeft];

        }

        

        [animation setDuration:0.2];

        [[selflayer] addAnimation:animationforKey:animationType];

        self.hidden=hidden;

    }


    @end




    //旋转图层


    - (void)startAnimationOfBookShelf {

        

        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];

        animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-2 * M_PI, 0, 0, -1.0)];

        animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-M_PI, 0, 0, -1.0)];

        animation.duration = 150;

        animation.cumulative = YES;

        animation.repeatCount = INT_MAX;

        [self.layer setShouldRasterize:YES];

        [self.layer addAnimation:animation forKey:ANIMATION_NAME_OF_BOOK_SHELF];

    }




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

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

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

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值