ios 常用的30个动画效果

//  
  1. //  CoreAnimationEffect.h  
  2. //  CoreAnimationEffect  
  3. //  
  4. //  Created by VincentXue on 13-1-19.  
  5. //  Copyright (c) 2013年 VincentXue. All rights reserved.  
  6. //  
  7.    
  8. #import <Foundation/Foundation.h>  
  9.    
  10. /** 
  11.  !  导入QuartzCore.framework 
  12.  * 
  13.  *  Example: 
  14.  * 
  15.  *  Step.1 
  16.  * 
  17.  *      #import "CoreAnimationEffect.h" 
  18.  * 
  19.  *  Step.2 
  20.  * 
  21.  *      [CoreAnimationEffect animationMoveLeft:your view]; 
  22.  *   
  23.  */  
  24.    
  25.    
  26. @interface CoreAnimationEffect : NSObject  
  27.    
  28. #pragma mark - Custom Animation  
  29.    
  30. /** 
  31.  *   @brief 快速构建一个你自定义的动画,有以下参数供你设置. 
  32.  * 
  33.  *   @note  调用系统预置Type需要在调用类引入下句 
  34.  * 
  35.  *          #import <QuartzCore/QuartzCore.h> 
  36.  * 
  37.  *   @param type                动画过渡类型 
  38.  *   @param subType             动画过渡方向(子类型) 
  39.  *   @param duration            动画持续时间 
  40.  *   @param timingFunction      动画定时函数属性 
  41.  *   @param theView             需要添加动画的view. 
  42.  * 
  43.  * 
  44.  */  
  45.    
  46. + (void)showAnimationType:(NSString *)type  
  47.               withSubType:(NSString *)subType  
  48.                  duration:(CFTimeInterval)duration  
  49.            timingFunction:(NSString *)timingFunction  
  50.                      view:(UIView *)theView;  
  51.    
  52. #pragma mark - Preset Animation  
  53.    
  54. /** 
  55.  *  下面是一些常用的动画效果 
  56.  */  
  57.    
  58. // reveal  
  59. + (void)animationRevealFromBottom:(UIView *)view;  
  60. + (void)animationRevealFromTop:(UIView *)view;  
  61. + (void)animationRevealFromLeft:(UIView *)view;  
  62. + (void)animationRevealFromRight:(UIView *)view;  
  63.    
  64. // 渐隐渐消  
  65. + (void)animationEaseIn:(UIView *)view;  
  66. + (void)animationEaseOut:(UIView *)view;  
  67.    
  68. // 翻转  
  69. + (void)animationFlipFromLeft:(UIView *)view;  
  70. + (void)animationFlipFromRigh:(UIView *)view;  
  71.    
  72. // 翻页  
  73. + (void)animationCurlUp:(UIView *)view;  
  74. + (void)animationCurlDown:(UIView *)view;  
  75.    
  76. // push  
  77. + (void)animationPushUp:(UIView *)view;  
  78. + (void)animationPushDown:(UIView *)view;  
  79. + (void)animationPushLeft:(UIView *)view;  
  80. + (void)animationPushRight:(UIView *)view;  
  81.    
  82. // move  
  83. + (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration;  
  84. + (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration;  
  85. + (void)animationMoveLeft:(UIView *)view;  
  86. + (void)animationMoveRight:(UIView *)view;  
  87.    
  88. // 旋转缩放  
  89.    
  90. // 各种旋转缩放效果  
  91. + (void)animationRotateAndScaleEffects:(UIView *)view;  
  92.    
  93. // 旋转同时缩小放大效果  
  94. + (void)animationRotateAndScaleDownUp:(UIView *)view;  
  95.    
  96.    
  97.    
  98. #pragma mark - Private API  
  99.    
  100. /** 
  101.  *  下面动画里用到的某些属性在当前API里是不合法的,但是也可以用. 
  102.  */  
  103.    
  104. + (void)animationFlipFromTop:(UIView *)view;  
  105. + (void)animationFlipFromBottom:(UIView *)view;  
  106.    
  107. + (void)animationCubeFromLeft:(UIView *)view;  
  108. + (void)animationCubeFromRight:(UIView *)view;  
  109. + (void)animationCubeFromTop:(UIView *)view;  
  110. + (void)animationCubeFromBottom:(UIView *)view;  
  111.    
  112. + (void)animationSuckEffect:(UIView *)view;  
  113.    
  114. + (void)animationRippleEffect:(UIView *)view;  
  115.    
  116. + (void)animationCameraOpen:(UIView *)view;  
  117. + (void)animationCameraClose:(UIView *)view;  
  118.    
  119. @end  
  120.    
  121.    
  122.    
  123. //  
  124. //  CoreAnimationEffect.m  
  125. //  CoreAnimationEffect  
  126. //  
  127. //  Created by VincentXue on 13-1-19.  
  128. //  Copyright (c) 2013年 VincentXue. All rights reserved.  
  129. //  
  130.    
  131. #import "CoreAnimationEffect.h"  
  132.    
  133. #import <QuartzCore/QuartzCore.h>  
  134.    
  135. @implementation CoreAnimationEffect  
  136.    
  137. /** 
  138.  *  首先推荐一个不错的网站.   http://www.raywenderlich.com 
  139.  */  
  140.    
  141. #pragma mark - Custom Animation  
  142.    
  143. + (void)showAnimationType:(NSString *)type  
  144.               withSubType:(NSString *)subType  
  145.                  duration:(CFTimeInterval)duration  
  146.            timingFunction:(NSString *)timingFunction  
  147.                      view:(UIView *)theView  
  148. {  
  149.     /** CATransition 
  150.      * 
  151.      *  @see http://www.dreamingwish.com/dream-2012/the-concept-of-coreanimation-programming-guide.html 
  152.      *  @see http://geeklu.com/2012/09/animation-in-ios/ 
  153.      * 
  154.      *  CATransition 常用设置及属性注解如下: 
  155.      */  
  156.    
  157.     CATransition *animation = [CATransition animation];  
  158.        
  159.     /** delegate 
  160.      * 
  161.      *  动画的代理,如果你想在动画开始和结束的时候做一些事,可以设置此属性,它会自动回调两个代理方法. 
  162.      * 
  163.      *  @see CAAnimationDelegate    (按下command键点击) 
  164.      */  
  165.        
  166.     animation.delegate = self;  
  167.        
  168.     /** duration 
  169.      * 
  170.      *  动画持续时间 
  171.      */  
  172.        
  173.     animation.duration = duration;  
  174.        
  175.     /** timingFunction 
  176.      * 
  177.      *  用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是均匀变化(相同时间变化量相同)还是 
  178.      *  先快后慢,先慢后快还是先慢再快再慢. 
  179.      * 
  180.      *  动画的开始与结束的快慢,有五个预置分别为(下同): 
  181.      *  kCAMediaTimingFunctionLinear            线性,即匀速 
  182.      *  kCAMediaTimingFunctionEaseIn            先慢后快 
  183.      *  kCAMediaTimingFunctionEaseOut           先快后慢 
  184.      *  kCAMediaTimingFunctionEaseInEaseOut     先慢后快再慢 
  185.      *  kCAMediaTimingFunctionDefault           实际效果是动画中间比较快. 
  186.      */  
  187.        
  188.     /** timingFunction 
  189.      * 
  190.      *  当上面的预置不能满足你的需求的时候,你可以使用下面的两个方法来自定义你的timingFunction 
  191.      *  具体参见下面的URL 
  192.      * 
  193.      *  @see http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CAMediaTimingFunction_class/Introduction/Introduction.html 
  194.      * 
  195.      *  + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y; 
  196.      * 
  197.      *  - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y; 
  198.      */  
  199.        
  200.     animation.timingFunction = [CAMediaTimingFunction functionWithName:timingFunction];  
  201.        
  202.     /** fillMode 
  203.      * 
  204.      *  决定当前对象过了非active时间段的行为,比如动画开始之前,动画结束之后. 
  205.      *  预置为: 
  206.      *  kCAFillModeRemoved   默认,当动画开始前和动画结束后,动画对layer都没有影响,动画结束后,layer会恢复到之前的状态 
  207.      *  kCAFillModeForwards  当动画结束后,layer会一直保持着动画最后的状态 
  208.      *  kCAFillModeBackwards 和kCAFillModeForwards相对,具体参考上面的URL 
  209.      *  kCAFillModeBoth      kCAFillModeForwards和kCAFillModeBackwards在一起的效果 
  210.      */  
  211.        
  212.     animation.fillMode = kCAFillModeForwards;  
  213.        
  214.     /** removedOnCompletion 
  215.      * 
  216.      *  这个属性默认为YES.一般情况下,不需要设置这个属性. 
  217.      * 
  218.      *  但如果是CAAnimation动画,并且需要设置 fillMode 属性,那么需要将 removedOnCompletion 设置为NO,否则 
  219.      *  fillMode无效 
  220.      */  
  221.        
  222. //    animation.removedOnCompletion = NO;  
  223.        
  224.     /** type 
  225.      * 
  226.      *  各种动画效果  其中除了'fade', `moveIn', `push' , `reveal' ,其他属于似有的API(我是这么认为的,可以点进去看下注释). 
  227.      *  ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用. 
  228.      *  @"cube"                     立方体翻滚效果 
  229.      *  @"moveIn"                   新视图移到旧视图上面 
  230.      *  @"reveal"                   显露效果(将旧视图移开,显示下面的新视图) 
  231.      *  @"fade"                     交叉淡化过渡(不支持过渡方向)             (默认为此效果) 
  232.      *  @"pageCurl"                 向上翻一页 
  233.      *  @"pageUnCurl"               向下翻一页 
  234.      *  @"suckEffect"               收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向) 
  235.      *  @"rippleEffect"             滴水效果,(不支持过渡方向) 
  236.      *  @"oglFlip"                  上下左右翻转效果 
  237.      *  @"rotate"                   旋转效果 
  238.      *  @"push"                      
  239.      *  @"cameraIrisHollowOpen"     相机镜头打开效果(不支持过渡方向) 
  240.      *  @"cameraIrisHollowClose"    相机镜头关上效果(不支持过渡方向) 
  241.      */  
  242.        
  243.     /** type 
  244.      * 
  245.      *  kCATransitionFade            交叉淡化过渡 
  246.      *  kCATransitionMoveIn          新视图移到旧视图上面 
  247.      *  kCATransitionPush            新视图把旧视图推出去 
  248.      *  kCATransitionReveal          将旧视图移开,显示下面的新视图 
  249.      */  
  250.        
  251.     animation.type = type;  
  252.        
  253.     /** subtype 
  254.      * 
  255.      *  各种动画方向 
  256.      * 
  257.      *  kCATransitionFromRight;      同字面意思(下同) 
  258.      *  kCATransitionFromLeft; 
  259.      *  kCATransitionFromTop; 
  260.      *  kCATransitionFromBottom; 
  261.      */  
  262.        
  263.     /** subtype 
  264.      * 
  265.      *  当type为@"rotate"(旋转)的时候,它也有几个对应的subtype,分别为: 
  266.      *  90cw    逆时针旋转90° 
  267.      *  90ccw   顺时针旋转90° 
  268.      *  180cw   逆时针旋转180° 
  269.      *  180ccw  顺时针旋转180° 
  270.      */  
  271.        
  272.     /** 
  273.      *  type与subtype的对应关系(必看),如果对应错误,动画不会显现. 
  274.      * 
  275.      *  @see http://iphonedevwiki.net/index.php/CATransition 
  276.      */  
  277.        
  278.     animation.subtype = subType;  
  279.        
  280.     /** 
  281.      *  所有核心动画和特效都是基于CAAnimation,而CAAnimation是作用于CALayer的.所以把动画添加到layer上. 
  282.      *  forKey  可以是任意字符串. 
  283.      */  
  284.        
  285.     [theView.layer addAnimation:animation forKey:nil];  
  286. }  
  287.    
  288. #pragma mark - Preset Animation  
  289.    
  290.    
  291. + (void)animationRevealFromBottom:(UIView *)view  
  292. {  
  293.     CATransition *animation = [CATransition animation];  
  294.     [animation setDuration:0.35f];  
  295.     [animation setType:kCATransitionReveal];  
  296.     [animation setSubtype:kCATransitionFromBottom];  
  297.     [animation setFillMode:kCAFillModeForwards];  
  298.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];  
  299.        
  300.     [view.layer addAnimation:animation forKey:nil];  
  301. }  
  302.    
  303. + (void)animationRevealFromTop:(UIView *)view  
  304. {  
  305.     CATransition *animation = [CATransition animation];  
  306.     [animation setDuration:0.35f];  
  307.     [animation setType:kCATransitionReveal];  
  308.     [animation setSubtype:kCATransitionFromTop];  
  309.     [animation setFillMode:kCAFillModeForwards];  
  310.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  311.        
  312.     [view.layer addAnimation:animation forKey:nil];  
  313. }  
  314.    
  315. + (void)animationRevealFromLeft:(UIView *)view  
  316. {  
  317.     CATransition *animation = [CATransition animation];  
  318.     [animation setDuration:0.35f];  
  319.     [animation setType:kCATransitionReveal];  
  320.     [animation setSubtype:kCATransitionFromLeft];  
  321.     [animation setFillMode:kCAFillModeForwards];  
  322.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];  
  323.        
  324.     [view.layer addAnimation:animation forKey:nil];  
  325. }  
  326.    
  327. + (void)animationRevealFromRight:(UIView *)view  
  328. {  
  329.     CATransition *animation = [CATransition animation];  
  330.     [animation setDuration:0.35f];  
  331.     [animation setType:kCATransitionReveal];  
  332.     [animation setSubtype:kCATransitionFromRight];  
  333.     [animation setFillMode:kCAFillModeForwards];  
  334.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];  
  335.        
  336.     [view.layer addAnimation:animation forKey:nil];  
  337. }  
  338.    
  339.    
  340. + (void)animationEaseIn:(UIView *)view  
  341. {  
  342.     CATransition *animation = [CATransition animation];  
  343.     [animation setDuration:0.35f];  
  344.     [animation setType:kCATransitionFade];  
  345.     [animation setFillMode:kCAFillModeForwards];  
  346.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];  
  347.        
  348.     [view.layer addAnimation:animation forKey:nil];  
  349. }  
  350.    
  351. + (void)animationEaseOut:(UIView *)view  
  352. {  
  353.     CATransition *animation = [CATransition animation];  
  354.     [animation setDuration:0.35f];  
  355.     [animation setType:kCATransitionFade];  
  356.     [animation setFillMode:kCAFillModeForwards];  
  357.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  358.        
  359.     [view.layer addAnimation:animation forKey:nil];  
  360. }  
  361.    
  362.    
  363. /** 
  364.  *  UIViewAnimation 
  365.  * 
  366.  *  @see    http://www.cocoachina.com/bbs/read.php?tid=110168 
  367.  * 
  368.  *  @brief  UIView动画应该是最简单便捷创建动画的方式了,详解请猛戳URL. 
  369.  *   
  370.  *  @method beginAnimations:context 第一个参数用来作为动画的标识,第二个参数给代理代理传递消息.至于为什么一个使用 
  371.  *                                  nil而另外一个使用NULL,是因为第一个参数是一个对象指针,而第二个参数是基本数据类型. 
  372.  *  @method setAnimationCurve:      设置动画的加速或减速的方式(速度) 
  373.  *  @method setAnimationDuration:   动画持续时间 
  374.  *  @method setAnimationTransition:forView:cache:   第一个参数定义动画类型,第二个参数是当前视图对象,第三个参数是是否使用缓冲区 
  375.  *  @method commitAnimations        动画结束 
  376.  */  
  377.    
  378. + (void)animationFlipFromLeft:(UIView *)view  
  379. {  
  380.     [UIView beginAnimations:nil context:NULL];  
  381.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  382.     [UIView setAnimationDuration:0.35f];  
  383.     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:NO];  
  384.     [UIView commitAnimations];  
  385. }  
  386.    
  387. + (void)animationFlipFromRigh:(UIView *)view  
  388. {  
  389.     [UIView beginAnimations:nil context:NULL];  
  390.     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  391.     [UIView setAnimationDuration:0.35f];  
  392.     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:NO];  
  393.     [UIView commitAnimations];  
  394. }  
  395.    
  396.    
  397. + (void)animationCurlUp:(UIView *)view  
  398. {  
  399.     [UIView beginAnimations:nil context:NULL];  
  400.     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];  
  401.     [UIView setAnimationDuration:0.35f];  
  402.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:NO];  
  403.     [UIView commitAnimations];  
  404. }  
  405.    
  406. + (void)animationCurlDown:(UIView *)view  
  407. {  
  408.     [UIView beginAnimations:nil context:NULL];  
  409.     [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];  
  410.     [UIView setAnimationDuration:0.35f];  
  411.     [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:view cache:NO];  
  412.     [UIView commitAnimations];  
  413. }  
  414.    
  415. + (void)animationPushUp:(UIView *)view  
  416. {  
  417.     CATransition *animation = [CATransition animation];  
  418.     [animation setDuration:0.35f];  
  419.     [animation setFillMode:kCAFillModeForwards];  
  420.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  421.     [animation setType:kCATransitionPush];  
  422.     [animation setSubtype:kCATransitionFromTop];  
  423.        
  424.     [view.layer addAnimation:animation forKey:nil];  
  425. }  
  426.    
  427. + (void)animationPushDown:(UIView *)view  
  428. {  
  429.     CATransition *animation = [CATransition animation];  
  430.     [animation setDuration:0.35f];  
  431.     [animation setFillMode:kCAFillModeForwards];  
  432.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  433.     [animation setType:kCATransitionPush];  
  434.     [animation setSubtype:kCATransitionFromBottom];  
  435.        
  436.     [view.layer addAnimation:animation forKey:nil];  
  437. }  
  438.    
  439. + (void)animationPushLeft:(UIView *)view  
  440. {  
  441.     CATransition *animation = [CATransition animation];  
  442.     [animation setDuration:0.35f];  
  443.     [animation setFillMode:kCAFillModeForwards];  
  444.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  445.     [animation setType:kCATransitionPush];  
  446.     [animation setSubtype:kCATransitionFromLeft];  
  447.        
  448.     [view.layer addAnimation:animation forKey:nil];  
  449. }  
  450.    
  451. + (void)animationPushRight:(UIView *)view  
  452. {  
  453.     CATransition *animation = [CATransition animation];  
  454.     [animation setDuration:0.35f];  
  455.     [animation setFillMode:kCAFillModeForwards];  
  456.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  457.     [animation setType:kCATransitionPush];  
  458.     [animation setSubtype:kCATransitionFromRight];  
  459.        
  460.     [view.layer addAnimation:animation forKey:nil];  
  461. }  
  462.    
  463. // presentModalViewController  
  464. + (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration  
  465. {  
  466.     CATransition *animation = [CATransition animation];  
  467.     [animation setDuration:duration];  
  468.     [animation setFillMode:kCAFillModeForwards];  
  469.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];  
  470.     [animation setType:kCATransitionMoveIn];  
  471.     [animation setSubtype:kCATransitionFromTop];  
  472.        
  473.     [view.layer addAnimation:animation forKey:nil];  
  474. }  
  475.    
  476. // dissModalViewController  
  477. + (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration  
  478. {  
  479.     CATransition *transition = [CATransition animation];  
  480.     transition.duration =0.4;  
  481.     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];  
  482.     transition.type = kCATransitionReveal;  
  483.     transition.subtype = kCATransitionFromBottom;  
  484.     [view.layer addAnimation:transition forKey:nil];  
  485. }  
  486.    
  487. + (void)animationMoveLeft:(UIView *)view  
  488. {  
  489.     CATransition *animation = [CATransition animation];  
  490.     [animation setDuration:0.35f];  
  491.     [animation setFillMode:kCAFillModeForwards];  
  492.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  493.     [animation setType:kCATransitionMoveIn];  
  494.     [animation setSubtype:kCATransitionFromLeft];  
  495.        
  496.     [view.layer addAnimation:animation forKey:nil];  
  497. }  
  498.    
  499. + (void)animationMoveRight:(UIView *)view  
  500. {  
  501.     CATransition *animation = [CATransition animation];  
  502.     [animation setDuration:0.35f];  
  503.     [animation setFillMode:kCAFillModeForwards];  
  504.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  505.     [animation setType:kCATransitionMoveIn];  
  506.     [animation setSubtype:kCATransitionFromRight];  
  507.        
  508.     [view.layer addAnimation:animation forKey:nil];  
  509. }  
  510.    
  511. +(void)animationRotateAndScaleEffects:(UIView *)view  
  512. {  
  513.     [UIView animateWithDuration:0.35f animations:^  
  514.      {  
  515.          /** 
  516.           *  @see       http://donbe.blog.163.com/blog/static/138048021201061054243442/ 
  517.           * 
  518.           *  @param     transform   形变属性(结构体),可以利用这个属性去对view做一些翻转或者缩放.详解请猛戳↑URL. 
  519.           * 
  520.           *  @method    valueWithCATransform3D: 此方法需要一个CATransform3D的结构体.一些非详细的讲解可以看下面的URL 
  521.           * 
  522.           *  @see       http://blog.csdn.net/liubo0_0/article/details/7452166 
  523.           * 
  524.           */  
  525.             
  526.          view.transform = CGAffineTransformMakeScale(0.001, 0.001);  
  527.             
  528.          CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];  
  529.             
  530.          // 向右旋转45°缩小到最小,然后再从小到大推出.  
  531.          animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.70, 0.40, 0.80)];  
  532.             
  533.          /** 
  534.           *     其他效果: 
  535.           *     从底部向上收缩一半后弹出 
  536.           *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0)]; 
  537.           * 
  538.           *     从底部向上完全收缩后弹出 
  539.           *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1.0, 0.0, 0.0)]; 
  540.           * 
  541.           *     左旋转45°缩小到最小,然后再从小到大推出. 
  542.           *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.50, -0.50, 0.50)]; 
  543.           * 
  544.           *     旋转180°缩小到最小,然后再从小到大推出. 
  545.           *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.1, 0.2, 0.2)]; 
  546.           */  
  547.             
  548.          animation.duration = 0.45;  
  549.          animation.repeatCount = 1;  
  550.          [view.layer addAnimation:animation forKey:nil];  
  551.             
  552.      }  
  553.                      completion:^(BOOL finished)  
  554.      {  
  555.          [UIView animateWithDuration:0.35f animations:^  
  556.           {  
  557.               view.transform = CGAffineTransformMakeScale(1.0, 1.0);  
  558.           }];  
  559.      }];  
  560. }  
  561.    
  562. /** CABasicAnimation 
  563.  * 
  564.  *  @see https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreAnimation_guide/Articles/KVCAdditions.html 
  565.  * 
  566.  *  @brief                      便利构造函数 animationWithKeyPath: KeyPath需要一个字符串类型的参数,实际上是一个 
  567.  *                              键-值编码协议的扩展,参数必须是CALayer的某一项属性,你的代码会对应的去改变该属性的效果 
  568.  *                              具体可以填写什么请参考上面的URL,切勿乱填! 
  569.  *                              例如这里填写的是 @"transform.rotation.z" 意思就是围绕z轴旋转,旋转的单位是弧度. 
  570.  *                              这个动画的效果是把view旋转到最小,再旋转回来. 
  571.  *                              你也可以填写@"opacity" 去修改透明度...以此类推.修改layer的属性,可以用这个类. 
  572.  * 
  573.  *  @param toValue              动画结束的值.CABasicAnimation自己只有三个属性(都很重要)(其他属性是继承来的),分别为: 
  574.  *                              fromValue(开始值), toValue(结束值), byValue(偏移值), 
  575.  !                              这三个属性最多只能同时设置两个; 
  576.  *                              他们之间的关系如下: 
  577.  *                              如果同时设置了fromValue和toValue,那么动画就会从fromValue过渡到toValue; 
  578.  *                              如果同时设置了fromValue和byValue,那么动画就会从fromValue过渡到fromValue + byValue; 
  579.  *                              如果同时设置了byValue  和toValue,那么动画就会从toValue - byValue过渡到toValue; 
  580.  * 
  581.  *                              如果只设置了fromValue,那么动画就会从fromValue过渡到当前的value; 
  582.  *                              如果只设置了toValue  ,那么动画就会从当前的value过渡到toValue; 
  583.  *                              如果只设置了byValue  ,那么动画就会从从当前的value过渡到当前value + byValue. 
  584.  * 
  585.  *                              可以这么理解,当你设置了三个中的一个或多个,系统就会根据以上规则使用插值算法计算出一个时间差并 
  586.  *                              同时开启一个Timer.Timer的间隔也就是这个时间差,通过这个Timer去不停地刷新keyPath的值. 
  587.  !                              而实际上,keyPath的值(layer的属性)在动画运行这一过程中,是没有任何变化的,它只是调用了GPU去 
  588.  *                              完成这些显示效果而已. 
  589.  *                              在这个动画里,是设置了要旋转到的弧度,根据以上规则,动画将会从它当前的弧度专旋转到我设置的弧度. 
  590.  * 
  591.  *  @param duration             动画持续时间 
  592.  * 
  593.  *  @param timingFunction       动画起点和终点之间的插值计算,也就是说它决定了动画运行的节奏,是快还是慢,还是先快后慢... 
  594.  */  
  595.    
  596. /** CAAnimationGroup 
  597.  * 
  598.  *  @brief                      顾名思义,这是一个动画组,它允许多个动画组合在一起并行显示.比如这里设置了两个动画, 
  599.  *                              把他们加在动画组里,一起显示.例如你有几个动画,在动画执行的过程中需要同时修改动画的某些属性, 
  600.  *                              这时候就可以使用CAAnimationGroup. 
  601.  * 
  602.  *  @param duration             动画持续时间,值得一提的是,如果添加到group里的子动画不设置此属性,group里的duration会统一 
  603.  *                              设置动画(包括子动画)的duration属性;但是如果子动画设置了duration属性,那么group的duration属性 
  604.  *                              的值不应该小于每个子动画中duration属性的值,否则会造成子动画显示不全就停止了动画. 
  605.  * 
  606.  *  @param autoreverses         动画完成后自动重新开始,默认为NO. 
  607.  * 
  608.  *  @param repeatCount          动画重复次数,默认为0. 
  609.  * 
  610.  *  @param animations           动画组(数组类型),把需要同时运行的动画加到这个数组里. 
  611.  * 
  612.  *  @note  addAnimation:forKey  这个方法的forKey参数是一个字符串,这个字符串可以随意设置. 
  613.  * 
  614.  *  @note                       如果你需要在动画group执行结束后保存动画效果的话,设置 fillMode 属性,并且把 
  615.  *                              removedOnCompletion 设置为NO; 
  616.  */  
  617.    
  618. + (void)animationRotateAndScaleDownUp:(UIView *)view  
  619. {  
  620.     CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];  
  621.  rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];  
  622.  rotationAnimation.duration = 0.35f;  
  623.  rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];  
  624.        
  625.  CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];  
  626.  scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];  
  627.  scaleAnimation.duration = 0.35f;  
  628.  scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];  
  629.     
  630.  CAAnimationGroup *animationGroup = [CAAnimationGroup animation];  
  631.  animationGroup.duration = 0.35f;  
  632.  animationGroup.autoreverses = YES;  
  633.  animationGroup.repeatCount = 1;  
  634.  animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil];  
  635.  [view.layer addAnimation:animationGroup forKey:@"animationGroup"];  
  636. }  
  637.    
  638.    
  639.    
  640. #pragma mark - Private API  
  641.    
  642. + (void)animationFlipFromTop:(UIView *)view  
  643. {  
  644.     CATransition *animation = [CATransition animation];  
  645.     [animation setDuration:0.35f];  
  646.     [animation setFillMode:kCAFillModeForwards];  
  647.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  648.     [animation setType:@"oglFlip"];  
  649.     [animation setSubtype:@"fromTop"];  
  650.        
  651.     [view.layer addAnimation:animation forKey:nil];  
  652. }  
  653.    
  654. + (void)animationFlipFromBottom:(UIView *)view  
  655. {  
  656.     CATransition *animation = [CATransition animation];  
  657.     [animation setDuration:0.35f];  
  658.     [animation setFillMode:kCAFillModeForwards];  
  659.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  660.     [animation setType:@"oglFlip"];  
  661.     [animation setSubtype:@"fromBottom"];  
  662.        
  663.     [view.layer addAnimation:animation forKey:nil];  
  664. }  
  665.    
  666. + (void)animationCubeFromLeft:(UIView *)view  
  667. {  
  668.     CATransition *animation = [CATransition animation];  
  669.     [animation setDuration:0.35f];  
  670.     [animation setFillMode:kCAFillModeForwards];  
  671.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  672.     [animation setType:@"cube"];  
  673.     [animation setSubtype:@"fromLeft"];  
  674.        
  675.     [view.layer addAnimation:animation forKey:nil];  
  676. }  
  677.    
  678. + (void)animationCubeFromRight:(UIView *)view  
  679. {  
  680.     CATransition *animation = [CATransition animation];  
  681.     [animation setDuration:0.35f];  
  682.     [animation setFillMode:kCAFillModeForwards];  
  683.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  684.     [animation setType:@"cube"];  
  685.     [animation setSubtype:@"fromRight"];  
  686.        
  687.     [view.layer addAnimation:animation forKey:nil];  
  688. }  
  689.    
  690. + (void)animationCubeFromTop:(UIView *)view  
  691. {  
  692.     CATransition *animation = [CATransition animation];  
  693.     [animation setDuration:0.35f];  
  694.     [animation setFillMode:kCAFillModeForwards];  
  695.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  696.     [animation setType:@"cube"];  
  697.     [animation setSubtype:@"fromTop"];  
  698.        
  699.     [view.layer addAnimation:animation forKey:nil];  
  700. }  
  701.    
  702. + (void)animationCubeFromBottom:(UIView *)view  
  703. {  
  704.     CATransition *animation = [CATransition animation];  
  705.     [animation setDuration:0.35f];  
  706.     [animation setFillMode:kCAFillModeForwards];  
  707.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  708.     [animation setType:@"cube"];  
  709.     [animation setSubtype:@"fromBottom"];  
  710.        
  711.     [view.layer addAnimation:animation forKey:nil];  
  712. }  
  713.    
  714. + (void)animationSuckEffect:(UIView *)view  
  715. {  
  716.     CATransition *animation = [CATransition animation];  
  717.     [animation setDuration:0.35f];  
  718.     [animation setFillMode:kCAFillModeForwards];  
  719.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  720.     [animation setType:@"suckEffect"];  
  721.        
  722.     [view.layer addAnimation:animation forKey:nil];  
  723. }  
  724.    
  725. + (void)animationRippleEffect:(UIView *)view  
  726. {  
  727.     CATransition *animation = [CATransition animation];  
  728.     [animation setDuration:0.35f];  
  729.     [animation setFillMode:kCAFillModeForwards];  
  730.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  731.     [animation setType:@"rippleEffect"];  
  732.        
  733.     [view.layer addAnimation:animation forKey:nil];  
  734. }  
  735.    
  736. + (void)animationCameraOpen:(UIView *)view  
  737. {  
  738.     CATransition *animation = [CATransition animation];  
  739.     [animation setDuration:0.35f];  
  740.     [animation setFillMode:kCAFillModeForwards];  
  741.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  742.     [animation setType:@"cameraIrisHollowOpen"];  
  743.     [animation setSubtype:@"fromRight"];  
  744.        
  745.     [view.layer addAnimation:animation forKey:nil];  
  746. }  
  747.    
  748. + (void)animationCameraClose:(UIView *)view  
  749. {  
  750.     CATransition *animation = [CATransition animation];  
  751.     [animation setDuration:0.35f];  
  752.     [animation setFillMode:kCAFillModeForwards];  
  753.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];  
  754.     [animation setType:@"cameraIrisHollowClose"];  
  755.     [animation setSubtype:@"fromRight"];  
  756.        
  757.     [view.layer addAnimation:animation forKey:nil];  
  758. }  
  759. @end  
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值