精华内容
下载资源
问答
  • iOS开发13-iOS动画的学习 1UIView动画 动画影响的属性 frame: 视图框架 center: 视图中心点 bounds: 视图边际 backgroundColor:背景颜色 alpha: 视图透明度 transform: 视图转换 frame: 该view在父view坐标...

    iOS开发13-iOS动画的学习



    1UIView动画

    动画影响的属性
    frame:     视图框架
    center:    视图中心点
    bounds:  视图边际
    backgroundColor:背景颜色
    alpha:        视图透明度
    transform: 视图转换

    frame:      该view在父view坐标系统中的位置和大小。(参照点是,父亲的坐标系统)

    bounds:该view在本地坐标系统中的位置和大小。(参照点是,本地坐标系统,就相当于View自己的坐标系统,以0,0点为起点)

    center:  该view的中心点在父view坐标系统中的位置和大小。(参照点是,父亲的坐标系统)

    1.1动画块

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.v1 = [[UIView alloc]init];
        self.v1.frame = CGRectMake(100, 100, 200, 200);
        self.v1.backgroundColor =[UIColor blueColor];
        [self.view addSubview:self.v1];
        }

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
      
        //开始动画
        [UIView beginAnimations:nil context:nil];//标记动画开始
        //设置各种动画属性
        /*
        //[UIView setAnimationDuration:(NSTimeInterval)]//设置动画持续时间
        //[UIView setAnimationDelay:(NSTimeInterval)]//设置动画开始前的延时
        //[UIView setAnimationRepeatAutoreverses:(BOOL)]//
        //[UIView setAnimationRepeatCount:(float)]//重复次数
        //[UIView setAnimationDelegate:(nullable id)]//设置动画的代理
        */
        
        //设置动画持续时间 2秒
        [UIView setAnimationDuration:5];
        //延迟开始         0.1秒后开始动画
        [UIView setAnimationDelay:0.1];
        //重复次数 1次
        [UIView setAnimationRepeatCount:1];
        //动画的速度曲线-开始结束的运行速度
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        //setAnimationCurve的枚举
        /*
         UIViewAnimationCurveEaseInOut,//开始和结束时候慢速
         UIViewAnimationCurveEaseIn,   //开始慢速
         UIViewAnimationCurveEaseOut,  //结束慢速
         UIViewAnimationCurveLinear    //线性,正常速度
         */
        
        //设置动画过渡到的效果
        //背景颜色
        self.v1.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
        //中心点
        //self.v1.center=CGPointMake(300, 300);
        //开始时候,V1在父View里的位置和大小:self.v1.frame = CGRectMake(100, 100, 200, 200);
        self.v1.frame = CGRectMake(300, 300, 30, 30);
        
        //提交动画
        [UIView commitAnimations];//标记动画结束
        
       }


    动画效果:


    1.2动画Block

    [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            
            //在这里设置各种属性
            self.fromView.backgroundColor=[UIColor greenColor];
            
                         } completion:^(BOOL finished) {
            
            //动画完成之后
            
                                      }];


    2CAAnimation动画

    2.1CABasicAnimation基本动画

    可以通过animationWithKeyPath键值对的方式来改变动画
    animationWithKeyPath的值:
      transform.scale = 比例转换
        transform.scale.x = 宽的比例转换
        transform.scale.y = 高的比例转换
        transform.rotation.z = 平面图的旋转
        opacity = 透明度
        margin
        zPosition
        backgroundColor    背景颜色
        cornerRadius    圆角
        borderWidth
        bounds
        contents
        contentsRect
        cornerRadius
        frame
        hidden
        mask
        masksToBounds
        position
        shadowColor
        shadowOffset
        shadowOpacity
        shadowRadius


    1、沿直线移动

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.v1=[[UIView alloc]init];
        self.v1.frame=CGRectMake(50, 50, 100, 100);
        self.v1.backgroundColor=[UIColor redColor];
        [self.view addSubview:self.v1];
        }


     //CABasicAnimation //基本动画
        //position
        //从一个位置到另外一个位置,沿着直线路径
        CABasicAnimation * basic1 = [CABasicAnimation animationWithKeyPath:@"position"];
        basic1.duration = 3.0f;//5秒
       
        //从哪儿开始
        NSValue *value1 = [NSValue valueWithCGPoint:self.v1.layer.position];
        basic1.fromValue = value1;
        
        //到哪里去
        NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(300, 400)];
         basic1.toValue =value2;
        
        
        [self.v1.layer addAnimation:basic1 forKey:@"position"];
        
        //不设置的话,动画结束后会回到原来的位置
        self.v1.layer.position=CGPointMake(300, 400);
        //移除动画
        //[self.v1.layer removeAnimationForKey:@"positon"];
        


    动画效果:




    2、旋转

    //旋转
        
        CABasicAnimation * basic2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        
        basic2.duration = 5;//5秒
      
        basic2.fromValue = @(0);
        
        basic2.toValue =@(M_PI*5);
        [self.v1.layer addAnimation:basic2 forKey:@"b2"];


    动画效果:



    3、放大缩小

     //放大缩小
        
        CABasicAnimation * basic3 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        
        basic3.duration = 5.f;//5秒
        
        basic3.fromValue = @(1);
        
        basic3.toValue =@(3);
        [self.v1.layer addAnimation:basic3 forKey:@"b3"];

    动画效果:




    2.2 CAKeyframeAnimation动画

    2.2.1按照给定路线移动

    // CAKeyframeAnimation
        
        //移动路线
        
        CAKeyframeAnimation *kf = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        
        kf.duration = 5.f;
        
        
        
        id p1 = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
        
        
        id p2 = [NSValue valueWithCGPoint:CGPointMake(350, 100)];
        
        id p3 = [NSValue valueWithCGPoint:CGPointMake(150, 550)];
        
        id p4 = [NSValue valueWithCGPoint:CGPointMake(350, 550)];
        
        
        
        kf.values=@[p1,p2,p3,p4];
        
        [self.v1.layer addAnimation:kf forKey:@"kf1"];

    动画效果:



    2.2.2连续变换颜色

     //变颜色
        
        CAKeyframeAnimation *kf2 =[CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
    
        
        
        kf2.duration = 5.f;
        //变化过程
        
        id c1 =(id)[UIColor blackColor].CGColor;
        
        id c2 =(id)[UIColor greenColor].CGColor;
        
        id c3 =(id)[UIColor yellowColor].CGColor;
        
        id c4 =(id)[UIColor redColor].CGColor;
        
        kf2.values=@[c1,c2,c3,c4];
        
        
        [self.v1.layer addAnimation:kf2 forKey:@"kf2"];
        
    动画效果:



    2.3 CAAnimationGroup组合动画

     //旋转
        
        CABasicAnimation * basic2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        
        basic2.duration = 5;//5秒
      
        basic2.fromValue = @(0);
        
        basic2.toValue =@(M_PI*5);
    
     //移动路线
        
        CAKeyframeAnimation *kf = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        
        kf.duration = 5.f;
        
        
        
        id p1 = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
        
        
        id p2 = [NSValue valueWithCGPoint:CGPointMake(350, 100)];
        
        id p3 = [NSValue valueWithCGPoint:CGPointMake(150, 550)];
        
        id p4 = [NSValue valueWithCGPoint:CGPointMake(350, 550)];
        
        
        
        kf.values=@[p1,p2,p3,p4];
     //变颜色
        
        CAKeyframeAnimation *kf2 =[CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
    
        
        
        kf2.duration = 5.f;
        //变化过程
        
        id c1 =(id)[UIColor blackColor].CGColor;
        
        id c2 =(id)[UIColor greenColor].CGColor;
        
        id c3 =(id)[UIColor yellowColor].CGColor;
        
        id c4 =(id)[UIColor redColor].CGColor;
        
        kf2.values=@[c1,c2,c3,c4];
     // CAAnimationGroup
        
        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.duration=5;
        group.animations = @[kf,kf2];
        
        //添加组合动画
        [self.v1.layer addAnimation:group forKey:@"group"];

    动画效果:





    2.4 CATransition动画

      CATransition *tran1 = [CATransition animation];
        tran1.duration = 5.f;
        //动画效果
        
      
        tran1.type = @"reveal";//类型 // fade, moveIn, push , reveal
         tran1.subtype = @"fromLeft";//方向
        /*
         fromLeft
         fromRight
         fromTop
         fromBottom
         */
        
        [self.v1.layer addAnimation:tran1 forKey:@"tran1"];
        

    动画效果:


    展开全文
  • iOS常用动画

    千次阅读 2013-06-24 17:39:38
    // // CoreAnimationEffect.h // CoreAnimationEffect ...// Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All rights reserved. // #import /** ! 导入QuartzCore.framework *
    //
    //  CoreAnimationEffect.h
    //  CoreAnimationEffect
    //
    //  Created by VincentXue on 13-1-19.
    //  Copyright (c) 2013年 VincentXue. All rights reserved.
    //
     
    #import <Foundation/Foundation.h>
     
    /**
     !  导入QuartzCore.framework
     *
     *  Example:
     *
     *  Step.1
     *
     *      #import "CoreAnimationEffect.h"
     *
     *  Step.2
     *
     *      [CoreAnimationEffect animationMoveLeft:your view];
     * 
     */
     
     
    @interface CoreAnimationEffect : NSObject
     
    #pragma mark - Custom Animation
     
    /**
     *   @brief 快速构建一个你自定义的动画,有以下参数供你设置.
     *
     *   @note  调用系统预置Type需要在调用类引入下句
     *
     *          #import <QuartzCore/QuartzCore.h>
     *
     *   @param type                动画过渡类型
     *   @param subType             动画过渡方向(子类型)
     *   @param duration            动画持续时间
     *   @param timingFunction      动画定时函数属性
     *   @param theView             需要添加动画的view.
     *
     *
     */
     
    + (void)showAnimationType:(NSString *)type
                  withSubType:(NSString *)subType
                     duration:(CFTimeInterval)duration
               timingFunction:(NSString *)timingFunction
                         view:(UIView *)theView;
     
    #pragma mark - Preset Animation
     
    /**
     *  下面是一些常用的动画效果
     */
     
    // reveal
    + (void)animationRevealFromBottom:(UIView *)view;
    + (void)animationRevealFromTop:(UIView *)view;
    + (void)animationRevealFromLeft:(UIView *)view;
    + (void)animationRevealFromRight:(UIView *)view;
     
    // 渐隐渐消
    + (void)animationEaseIn:(UIView *)view;
    + (void)animationEaseOut:(UIView *)view;
     
    // 翻转
    + (void)animationFlipFromLeft:(UIView *)view;
    + (void)animationFlipFromRigh:(UIView *)view;
     
    // 翻页
    + (void)animationCurlUp:(UIView *)view;
    + (void)animationCurlDown:(UIView *)view;
     
    // push
    + (void)animationPushUp:(UIView *)view;
    + (void)animationPushDown:(UIView *)view;
    + (void)animationPushLeft:(UIView *)view;
    + (void)animationPushRight:(UIView *)view;
     
    // move
    + (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration;
    + (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration;
    + (void)animationMoveLeft:(UIView *)view;
    + (void)animationMoveRight:(UIView *)view;
     
    // 旋转缩放
     
    // 各种旋转缩放效果
    + (void)animationRotateAndScaleEffects:(UIView *)view;
     
    // 旋转同时缩小放大效果
    + (void)animationRotateAndScaleDownUp:(UIView *)view;
     
     
     
    #pragma mark - Private API
     
    /**
     *  下面动画里用到的某些属性在当前API里是不合法的,但是也可以用.
     */
     
    + (void)animationFlipFromTop:(UIView *)view;
    + (void)animationFlipFromBottom:(UIView *)view;
     
    + (void)animationCubeFromLeft:(UIView *)view;
    + (void)animationCubeFromRight:(UIView *)view;
    + (void)animationCubeFromTop:(UIView *)view;
    + (void)animationCubeFromBottom:(UIView *)view;
     
    + (void)animationSuckEffect:(UIView *)view;
     
    + (void)animationRippleEffect:(UIView *)view;
     
    + (void)animationCameraOpen:(UIView *)view;
    + (void)animationCameraClose:(UIView *)view;
     
    @end
     
     
     
    //
    //  CoreAnimationEffect.m
    //  CoreAnimationEffect
    //
    //  Created by VincentXue on 13-1-19.
    //  Copyright (c) 2013年 VincentXue. All rights reserved.
    //
     
    #import "CoreAnimationEffect.h"
     
    #import <QuartzCore/QuartzCore.h>
     
    @implementation CoreAnimationEffect
     
    /**
     *  首先推荐一个不错的网站.   http://www.raywenderlich.com
     */
     
    #pragma mark - Custom Animation
     
    + (void)showAnimationType:(NSString *)type
                  withSubType:(NSString *)subType
                     duration:(CFTimeInterval)duration
               timingFunction:(NSString *)timingFunction
                         view:(UIView *)theView
    {
        /** CATransition
         *
         *  @see http://www.dreamingwish.com/dream-2012/the-concept-of-coreanimation-programming-guide.html
         *  @see http://geeklu.com/2012/09/animation-in-ios/
         *
         *  CATransition 常用设置及属性注解如下:
         */
     
        CATransition *animation = [CATransition animation];
         
        /** delegate
         *
         *  动画的代理,如果你想在动画开始和结束的时候做一些事,可以设置此属性,它会自动回调两个代理方法.
         *
         *  @see CAAnimationDelegate    (按下command键点击)
         */
         
        animation.delegate = self;
         
        /** duration
         *
         *  动画持续时间
         */
         
        animation.duration = duration;
         
        /** timingFunction
         *
         *  用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是均匀变化(相同时间变化量相同)还是
         *  先快后慢,先慢后快还是先慢再快再慢.
         *
         *  动画的开始与结束的快慢,有五个预置分别为(下同):
         *  kCAMediaTimingFunctionLinear            线性,即匀速
         *  kCAMediaTimingFunctionEaseIn            先慢后快
         *  kCAMediaTimingFunctionEaseOut           先快后慢
         *  kCAMediaTimingFunctionEaseInEaseOut     先慢后快再慢
         *  kCAMediaTimingFunctionDefault           实际效果是动画中间比较快.
         */
         
        /** timingFunction
         *
         *  当上面的预置不能满足你的需求的时候,你可以使用下面的两个方法来自定义你的timingFunction
         *  具体参见下面的URL
         *
         *  @see http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CAMediaTimingFunction_class/Introduction/Introduction.html
         *
         *  + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
         *
         *  - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
         */
         
        animation.timingFunction = [CAMediaTimingFunction functionWithName:timingFunction];
         
        /** fillMode
         *
         *  决定当前对象过了非active时间段的行为,比如动画开始之前,动画结束之后.
         *  预置为:
         *  kCAFillModeRemoved   默认,当动画开始前和动画结束后,动画对layer都没有影响,动画结束后,layer会恢复到之前的状态
         *  kCAFillModeForwards  当动画结束后,layer会一直保持着动画最后的状态
         *  kCAFillModeBackwards 和kCAFillModeForwards相对,具体参考上面的URL
         *  kCAFillModeBoth      kCAFillModeForwards和kCAFillModeBackwards在一起的效果
         */
         
        animation.fillMode = kCAFillModeForwards;
         
        /** removedOnCompletion
         *
         *  这个属性默认为YES.一般情况下,不需要设置这个属性.
         *
         *  但如果是CAAnimation动画,并且需要设置 fillMode 属性,那么需要将 removedOnCompletion 设置为NO,否则
         *  fillMode无效
         */
         
    //    animation.removedOnCompletion = NO;
         
        /** type
         *
         *  各种动画效果  其中除了'fade', `moveIn', `push' , `reveal' ,其他属于似有的API(我是这么认为的,可以点进去看下注释).
         *  ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
         *  @"cube"                     立方体翻滚效果
         *  @"moveIn"                   新视图移到旧视图上面
         *  @"reveal"                   显露效果(将旧视图移开,显示下面的新视图)
         *  @"fade"                     交叉淡化过渡(不支持过渡方向)             (默认为此效果)
         *  @"pageCurl"                 向上翻一页
         *  @"pageUnCurl"               向下翻一页
         *  @"suckEffect"               收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)
         *  @"rippleEffect"             滴水效果,(不支持过渡方向)
         *  @"oglFlip"                  上下左右翻转效果
         *  @"rotate"                   旋转效果
         *  @"push"                    
         *  @"cameraIrisHollowOpen"     相机镜头打开效果(不支持过渡方向)
         *  @"cameraIrisHollowClose"    相机镜头关上效果(不支持过渡方向)
         */
         
        /** type
         *
         *  kCATransitionFade            交叉淡化过渡
         *  kCATransitionMoveIn          新视图移到旧视图上面
         *  kCATransitionPush            新视图把旧视图推出去
         *  kCATransitionReveal          将旧视图移开,显示下面的新视图
         */
         
        animation.type = type;
         
        /** subtype
         *
         *  各种动画方向
         *
         *  kCATransitionFromRight;      同字面意思(下同)
         *  kCATransitionFromLeft;
         *  kCATransitionFromTop;
         *  kCATransitionFromBottom;
         */
         
        /** subtype
         *
         *  当type为@"rotate"(旋转)的时候,它也有几个对应的subtype,分别为:
         *  90cw    逆时针旋转90°
         *  90ccw   顺时针旋转90°
         *  180cw   逆时针旋转180°
         *  180ccw  顺时针旋转180°
         */
         
        /**
         *  type与subtype的对应关系(必看),如果对应错误,动画不会显现.
         *
         *  @see http://iphonedevwiki.net/index.php/CATransition
         */
         
        animation.subtype = subType;
         
        /**
         *  所有核心动画和特效都是基于CAAnimation,而CAAnimation是作用于CALayer的.所以把动画添加到layer上.
         *  forKey  可以是任意字符串.
         */
         
        [theView.layer addAnimation:animation forKey:nil];
    }
     
    #pragma mark - Preset Animation
     
     
    + (void)animationRevealFromBottom:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromBottom];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationRevealFromTop:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromTop];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationRevealFromLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromLeft];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationRevealFromRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromRight];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
     
    + (void)animationEaseIn:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionFade];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationEaseOut:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionFade];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
     
    /**
     *  UIViewAnimation
     *
     *  @see    http://www.cocoachina.com/bbs/read.php?tid=110168
     *
     *  @brief  UIView动画应该是最简单便捷创建动画的方式了,详解请猛戳URL.
     * 
     *  @method beginAnimations:context 第一个参数用来作为动画的标识,第二个参数给代理代理传递消息.至于为什么一个使用
     *                                  nil而另外一个使用NULL,是因为第一个参数是一个对象指针,而第二个参数是基本数据类型.
     *  @method setAnimationCurve:      设置动画的加速或减速的方式(速度)
     *  @method setAnimationDuration:   动画持续时间
     *  @method setAnimationTransition:forView:cache:   第一个参数定义动画类型,第二个参数是当前视图对象,第三个参数是是否使用缓冲区
     *  @method commitAnimations        动画结束
     */
     
    + (void)animationFlipFromLeft:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:NO];
        [UIView commitAnimations];
    }
     
    + (void)animationFlipFromRigh:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:NO];
        [UIView commitAnimations];
    }
     
     
    + (void)animationCurlUp:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:NO];
        [UIView commitAnimations];
    }
     
    + (void)animationCurlDown:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:view cache:NO];
        [UIView commitAnimations];
    }
     
    + (void)animationPushUp:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromTop];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationPushDown:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromBottom];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationPushLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromLeft];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationPushRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromRight];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    // presentModalViewController
    + (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:duration];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setType:kCATransitionMoveIn];
        [animation setSubtype:kCATransitionFromTop];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    // dissModalViewController
    + (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration
    {
        CATransition *transition = [CATransition animation];
        transition.duration =0.4;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type = kCATransitionReveal;
        transition.subtype = kCATransitionFromBottom;
        [view.layer addAnimation:transition forKey:nil];
    }
     
    + (void)animationMoveLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionMoveIn];
        [animation setSubtype:kCATransitionFromLeft];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationMoveRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionMoveIn];
        [animation setSubtype:kCATransitionFromRight];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    +(void)animationRotateAndScaleEffects:(UIView *)view
    {
        [UIView animateWithDuration:0.35f animations:^
         {
             /**
              *  @see       http://donbe.blog.163.com/blog/static/138048021201061054243442/
              *
              *  @param     transform   形变属性(结构体),可以利用这个属性去对view做一些翻转或者缩放.详解请猛戳↑URL.
              *
              *  @method    valueWithCATransform3D: 此方法需要一个CATransform3D的结构体.一些非详细的讲解可以看下面的URL
              *
              *  @see       http://blog.csdn.net/liubo0_0/article/details/7452166
              *
              */
              
             view.transform = CGAffineTransformMakeScale(0.001, 0.001);
              
             CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
              
             // 向右旋转45°缩小到最小,然后再从小到大推出.
             animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.70, 0.40, 0.80)];
              
             /**
              *     其他效果:
              *     从底部向上收缩一半后弹出
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0)];
              *
              *     从底部向上完全收缩后弹出
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1.0, 0.0, 0.0)];
              *
              *     左旋转45°缩小到最小,然后再从小到大推出.
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.50, -0.50, 0.50)];
              *
              *     旋转180°缩小到最小,然后再从小到大推出.
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.1, 0.2, 0.2)];
              */
              
             animation.duration = 0.45;
             animation.repeatCount = 1;
             [view.layer addAnimation:animation forKey:nil];
              
         }
                         completion:^(BOOL finished)
         {
             [UIView animateWithDuration:0.35f animations:^
              {
                  view.transform = CGAffineTransformMakeScale(1.0, 1.0);
              }];
         }];
    }
     
    /** CABasicAnimation
     *
     *  @see https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreAnimation_guide/Articles/KVCAdditions.html
     *
     *  @brief                      便利构造函数 animationWithKeyPath: KeyPath需要一个字符串类型的参数,实际上是一个
     *                              键-值编码协议的扩展,参数必须是CALayer的某一项属性,你的代码会对应的去改变该属性的效果
     *                              具体可以填写什么请参考上面的URL,切勿乱填!
     *                              例如这里填写的是 @"transform.rotation.z" 意思就是围绕z轴旋转,旋转的单位是弧度.
     *                              这个动画的效果是把view旋转到最小,再旋转回来.
     *                              你也可以填写@"opacity" 去修改透明度...以此类推.修改layer的属性,可以用这个类.
     *
     *  @param toValue              动画结束的值.CABasicAnimation自己只有三个属性(都很重要)(其他属性是继承来的),分别为:
     *                              fromValue(开始值), toValue(结束值), byValue(偏移值),
     !                              这三个属性最多只能同时设置两个;
     *                              他们之间的关系如下:
     *                              如果同时设置了fromValue和toValue,那么动画就会从fromValue过渡到toValue;
     *                              如果同时设置了fromValue和byValue,那么动画就会从fromValue过渡到fromValue + byValue;
     *                              如果同时设置了byValue  和toValue,那么动画就会从toValue - byValue过渡到toValue;
     *
     *                              如果只设置了fromValue,那么动画就会从fromValue过渡到当前的value;
     *                              如果只设置了toValue  ,那么动画就会从当前的value过渡到toValue;
     *                              如果只设置了byValue  ,那么动画就会从从当前的value过渡到当前value + byValue.
     *
     *                              可以这么理解,当你设置了三个中的一个或多个,系统就会根据以上规则使用插值算法计算出一个时间差并
     *                              同时开启一个Timer.Timer的间隔也就是这个时间差,通过这个Timer去不停地刷新keyPath的值.
     !                              而实际上,keyPath的值(layer的属性)在动画运行这一过程中,是没有任何变化的,它只是调用了GPU去
     *                              完成这些显示效果而已.
     *                              在这个动画里,是设置了要旋转到的弧度,根据以上规则,动画将会从它当前的弧度专旋转到我设置的弧度.
     *
     *  @param duration             动画持续时间
     *
     *  @param timingFunction       动画起点和终点之间的插值计算,也就是说它决定了动画运行的节奏,是快还是慢,还是先快后慢...
     */
     
    /** CAAnimationGroup
     *
     *  @brief                      顾名思义,这是一个动画组,它允许多个动画组合在一起并行显示.比如这里设置了两个动画,
     *                              把他们加在动画组里,一起显示.例如你有几个动画,在动画执行的过程中需要同时修改动画的某些属性,
     *                              这时候就可以使用CAAnimationGroup.
     *
     *  @param duration             动画持续时间,值得一提的是,如果添加到group里的子动画不设置此属性,group里的duration会统一
     *                              设置动画(包括子动画)的duration属性;但是如果子动画设置了duration属性,那么group的duration属性
     *                              的值不应该小于每个子动画中duration属性的值,否则会造成子动画显示不全就停止了动画.
     *
     *  @param autoreverses         动画完成后自动重新开始,默认为NO.
     *
     *  @param repeatCount          动画重复次数,默认为0.
     *
     *  @param animations           动画组(数组类型),把需要同时运行的动画加到这个数组里.
     *
     *  @note  addAnimation:forKey  这个方法的forKey参数是一个字符串,这个字符串可以随意设置.
     *
     *  @note                       如果你需要在动画group执行结束后保存动画效果的话,设置 fillMode 属性,并且把
     *                              removedOnCompletion 设置为NO;
     */
     
    + (void)animationRotateAndScaleDownUp:(UIView *)view
    {
        CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
     rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];
     rotationAnimation.duration = 0.35f;
     rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
         
     CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
     scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];
     scaleAnimation.duration = 0.35f;
     scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
      
     CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
     animationGroup.duration = 0.35f;
     animationGroup.autoreverses = YES;
     animationGroup.repeatCount = 1;
     animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil];
     [view.layer addAnimation:animationGroup forKey:@"animationGroup"];
    }
     
     
     
    #pragma mark - Private API
     
    + (void)animationFlipFromTop:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"oglFlip"];
        [animation setSubtype:@"fromTop"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationFlipFromBottom:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"oglFlip"];
        [animation setSubtype:@"fromBottom"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationCubeFromLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromLeft"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationCubeFromRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromRight"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationCubeFromTop:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromTop"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationCubeFromBottom:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromBottom"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationSuckEffect:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"suckEffect"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationRippleEffect:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"rippleEffect"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationCameraOpen:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cameraIrisHollowOpen"];
        [animation setSubtype:@"fromRight"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
     
    + (void)animationCameraClose:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cameraIrisHollowClose"];
        [animation setSubtype:@"fromRight"];
         
        [view.layer addAnimation:animation forKey:nil];
    }
    @end


    展开全文
  • ios常用动画

    2019-08-10 22:35:56
    //转自:... //读书人学习不算偷 //自己定义一个类CoreAnimationEffect // CoreAnimationEffect.h // CoreAnimationEffect ...// Created by VincentXue on 13-1...

    //转自:http://www.open-open.com/lib/view/open1372152939072.html

    //读书人学习不算偷

     //自己定义一个类CoreAnimationEffect

    //  CoreAnimationEffect.h
    //  CoreAnimationEffect
    //
    //  Created by VincentXue on 13-1-19.
    //  Copyright (c) 2013年 VincentXue. All rights reserved.
    //
      
    #import <Foundation/Foundation.h>
      
    /**
     !  导入QuartzCore.framework
     *
     *  Example:
     *
     *  Step.1
     *
     *      #import "CoreAnimationEffect.h"
     *
     *  Step.2
     *
     *      [CoreAnimationEffect animationMoveLeft:your view];
     *
     */
      
      
    @interface CoreAnimationEffect : NSObject
      
    #pragma mark - Custom Animation
      
    /**
     *   @brief 快速构建一个你自定义的动画,有以下参数供你设置.
     *
     *   @note  调用系统预置Type需要在调用类引入下句
     *
     *          #import <QuartzCore/QuartzCore.h>
     *
     *   @param type                动画过渡类型
     *   @param subType             动画过渡方向(子类型)
     *   @param duration            动画持续时间
     *   @param timingFunction      动画定时函数属性
     *   @param theView             需要添加动画的view.
     *
     *
     */
      
    + (void)showAnimationType:(NSString *)type
                  withSubType:(NSString *)subType
                     duration:(CFTimeInterval)duration
               timingFunction:(NSString *)timingFunction
                         view:(UIView *)theView;
      
    #pragma mark - Preset Animation
      
    /**
     *  下面是一些常用的动画效果
     */
      
    // reveal
    + (void)animationRevealFromBottom:(UIView *)view;
    + (void)animationRevealFromTop:(UIView *)view;
    + (void)animationRevealFromLeft:(UIView *)view;
    + (void)animationRevealFromRight:(UIView *)view;
      
    // 渐隐渐消
    + (void)animationEaseIn:(UIView *)view;
    + (void)animationEaseOut:(UIView *)view;
      
    // 翻转
    + (void)animationFlipFromLeft:(UIView *)view;
    + (void)animationFlipFromRigh:(UIView *)view;
      
    // 翻页
    + (void)animationCurlUp:(UIView *)view;
    + (void)animationCurlDown:(UIView *)view;
      
    // push
    + (void)animationPushUp:(UIView *)view;
    + (void)animationPushDown:(UIView *)view;
    + (void)animationPushLeft:(UIView *)view;
    + (void)animationPushRight:(UIView *)view;
      
    // move
    + (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration;
    + (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration;
    + (void)animationMoveLeft:(UIView *)view;
    + (void)animationMoveRight:(UIView *)view;
      
    // 旋转缩放
      
    // 各种旋转缩放效果
    + (void)animationRotateAndScaleEffects:(UIView *)view;
      
    // 旋转同时缩小放大效果
    + (void)animationRotateAndScaleDownUp:(UIView *)view;
      
      
      
    #pragma mark - Private API
      
    /**
     *  下面动画里用到的某些属性在当前API里是不合法的,但是也可以用.
     */
      
    + (void)animationFlipFromTop:(UIView *)view;
    + (void)animationFlipFromBottom:(UIView *)view;
      
    + (void)animationCubeFromLeft:(UIView *)view;
    + (void)animationCubeFromRight:(UIView *)view;
    + (void)animationCubeFromTop:(UIView *)view;
    + (void)animationCubeFromBottom:(UIView *)view;
      
    + (void)animationSuckEffect:(UIView *)view;
      
    + (void)animationRippleEffect:(UIView *)view;
      
    + (void)animationCameraOpen:(UIView *)view;
    + (void)animationCameraClose:(UIView *)view;
      
    @end
      
      
      
    //
    //  CoreAnimationEffect.m
    //  CoreAnimationEffect
    //
    //  Created by VincentXue on 13-1-19.
    //  Copyright (c) 2013年 VincentXue. All rights reserved.
    //
      
    #import "CoreAnimationEffect.h"
      
    #import <QuartzCore/QuartzCore.h>
      
    @implementation CoreAnimationEffect
      
    /**
     *  首先推荐一个不错的网站.   http://www.raywenderlich.com
     */
      
    #pragma mark - Custom Animation
      
    + (void)showAnimationType:(NSString *)type
                  withSubType:(NSString *)subType
                     duration:(CFTimeInterval)duration
               timingFunction:(NSString *)timingFunction
                         view:(UIView *)theView
    {
        /** CATransition
         *
         *  @see http://www.dreamingwish.com/dream-2012/the-concept-of-coreanimation-programming-guide.html
         *  @see http://geeklu.com/2012/09/animation-in-ios/
         *
         *  CATransition 常用设置及属性注解如下:
         */
      
        CATransition *animation = [CATransition animation];
          
        /** delegate
         *
         *  动画的代理,如果你想在动画开始和结束的时候做一些事,可以设置此属性,它会自动回调两个代理方法.
         *
         *  @see CAAnimationDelegate    (按下command键点击)
         */
          
        animation.delegate = self;
          
        /** duration
         *
         *  动画持续时间
         */
          
        animation.duration = duration;
          
        /** timingFunction
         *
         *  用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是均匀变化(相同时间变化量相同)还是
         *  先快后慢,先慢后快还是先慢再快再慢.
         *
         *  动画的开始与结束的快慢,有五个预置分别为(下同):
         *  kCAMediaTimingFunctionLinear            线性,即匀速
         *  kCAMediaTimingFunctionEaseIn            先慢后快
         *  kCAMediaTimingFunctionEaseOut           先快后慢
         *  kCAMediaTimingFunctionEaseInEaseOut     先慢后快再慢
         *  kCAMediaTimingFunctionDefault           实际效果是动画中间比较快.
         */
          
        /** timingFunction
         *
         *  当上面的预置不能满足你的需求的时候,你可以使用下面的两个方法来自定义你的timingFunction
         *  具体参见下面的URL
         *
         *  @see http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CAMediaTimingFunction_class/Introduction/Introduction.html
         *
         *  + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
         *
         *  - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
         */
          
        animation.timingFunction = [CAMediaTimingFunction functionWithName:timingFunction];
          
        /** fillMode
         *
         *  决定当前对象过了非active时间段的行为,比如动画开始之前,动画结束之后.
         *  预置为:
         *  kCAFillModeRemoved   默认,当动画开始前和动画结束后,动画对layer都没有影响,动画结束后,layer会恢复到之前的状态
         *  kCAFillModeForwards  当动画结束后,layer会一直保持着动画最后的状态
         *  kCAFillModeBackwards 和kCAFillModeForwards相对,具体参考上面的URL
         *  kCAFillModeBoth      kCAFillModeForwards和kCAFillModeBackwards在一起的效果
         */
          
        animation.fillMode = kCAFillModeForwards;
          
        /** removedOnCompletion
         *
         *  这个属性默认为YES.一般情况下,不需要设置这个属性.
         *
         *  但如果是CAAnimation动画,并且需要设置 fillMode 属性,那么需要将 removedOnCompletion 设置为NO,否则
         *  fillMode无效
         */
          
    //    animation.removedOnCompletion = NO;
          
        /** type
         *
         *  各种动画效果  其中除了'fade', `moveIn', `push' , `reveal' ,其他属于似有的API(我是这么认为的,可以点进去看下注释).
         *  ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
         *  @"cube"                     立方体翻滚效果
         *  @"moveIn"                   新视图移到旧视图上面
         *  @"reveal"                   显露效果(将旧视图移开,显示下面的新视图)
         *  @"fade"                     交叉淡化过渡(不支持过渡方向)             (默认为此效果)
         *  @"pageCurl"                 向上翻一页
         *  @"pageUnCurl"               向下翻一页
         *  @"suckEffect"               收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)
         *  @"rippleEffect"             滴水效果,(不支持过渡方向)
         *  @"oglFlip"                  上下左右翻转效果
         *  @"rotate"                   旋转效果
         *  @"push"                   
         *  @"cameraIrisHollowOpen"     相机镜头打开效果(不支持过渡方向)
         *  @"cameraIrisHollowClose"    相机镜头关上效果(不支持过渡方向)
         */
          
        /** type
         *
         *  kCATransitionFade            交叉淡化过渡
         *  kCATransitionMoveIn          新视图移到旧视图上面
         *  kCATransitionPush            新视图把旧视图推出去
         *  kCATransitionReveal          将旧视图移开,显示下面的新视图
         */
          
        animation.type = type;
          
        /** subtype
         *
         *  各种动画方向
         *
         *  kCATransitionFromRight;      同字面意思(下同)
         *  kCATransitionFromLeft;
         *  kCATransitionFromTop;
         *  kCATransitionFromBottom;
         */
          
        /** subtype
         *
         *  当type为@"rotate"(旋转)的时候,它也有几个对应的subtype,分别为:
         *  90cw    逆时针旋转90°
         *  90ccw   顺时针旋转90°
         *  180cw   逆时针旋转180°
         *  180ccw  顺时针旋转180°
         */
          
        /**
         *  type与subtype的对应关系(必看),如果对应错误,动画不会显现.
         *
         *  @see http://iphonedevwiki.net/index.php/CATransition
         */
          
        animation.subtype = subType;
          
        /**
         *  所有核心动画和特效都是基于CAAnimation,而CAAnimation是作用于CALayer的.所以把动画添加到layer上.
         *  forKey  可以是任意字符串.
         */
          
        [theView.layer addAnimation:animation forKey:nil];
    }
      
    #pragma mark - Preset Animation
      
      
    + (void)animationRevealFromBottom:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromBottom];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationRevealFromTop:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromTop];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationRevealFromLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromLeft];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationRevealFromRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionReveal];
        [animation setSubtype:kCATransitionFromRight];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
      
    + (void)animationEaseIn:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionFade];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationEaseOut:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setType:kCATransitionFade];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
      
    /**
     *  UIViewAnimation
     *
     *  @see    http://www.cocoachina.com/bbs/read.php?tid=110168
     *
     *  @brief  UIView动画应该是最简单便捷创建动画的方式了,详解请猛戳URL.
     *
     *  @method beginAnimations:context 第一个参数用来作为动画的标识,第二个参数给代理代理传递消息.至于为什么一个使用
     *                                  nil而另外一个使用NULL,是因为第一个参数是一个对象指针,而第二个参数是基本数据类型.
     *  @method setAnimationCurve:      设置动画的加速或减速的方式(速度)
     *  @method setAnimationDuration:   动画持续时间
     *  @method setAnimationTransition:forView:cache:   第一个参数定义动画类型,第二个参数是当前视图对象,第三个参数是是否使用缓冲区
     *  @method commitAnimations        动画结束
     */
      
    + (void)animationFlipFromLeft:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:NO];
        [UIView commitAnimations];
    }
      
    + (void)animationFlipFromRigh:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:NO];
        [UIView commitAnimations];
    }
      
      
    + (void)animationCurlUp:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:NO];
        [UIView commitAnimations];
    }
      
    + (void)animationCurlDown:(UIView *)view
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDuration:0.35f];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:view cache:NO];
        [UIView commitAnimations];
    }
      
    + (void)animationPushUp:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromTop];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationPushDown:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromBottom];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationPushLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromLeft];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationPushRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromRight];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    // presentModalViewController
    + (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:duration];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setType:kCATransitionMoveIn];
        [animation setSubtype:kCATransitionFromTop];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    // dissModalViewController
    + (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration
    {
        CATransition *transition = [CATransition animation];
        transition.duration =0.4;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type = kCATransitionReveal;
        transition.subtype = kCATransitionFromBottom;
        [view.layer addAnimation:transition forKey:nil];
    }
      
    + (void)animationMoveLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionMoveIn];
        [animation setSubtype:kCATransitionFromLeft];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationMoveRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:kCATransitionMoveIn];
        [animation setSubtype:kCATransitionFromRight];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    +(void)animationRotateAndScaleEffects:(UIView *)view
    {
        [UIView animateWithDuration:0.35f animations:^
         {
             /**
              *  @see       http://donbe.blog.163.com/blog/static/138048021201061054243442/
              *
              *  @param     transform   形变属性(结构体),可以利用这个属性去对view做一些翻转或者缩放.详解请猛戳↑URL.
              *
              *  @method    valueWithCATransform3D: 此方法需要一个CATransform3D的结构体.一些非详细的讲解可以看下面的URL
              *
              *  @see       http://blog.csdn.net/liubo0_0/article/details/7452166
              *
              */
               
             view.transform = CGAffineTransformMakeScale(0.001, 0.001);
               
             CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
               
             // 向右旋转45°缩小到最小,然后再从小到大推出.
             animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.70, 0.40, 0.80)];
               
             /**
              *     其他效果:
              *     从底部向上收缩一半后弹出
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0)];
              *
              *     从底部向上完全收缩后弹出
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1.0, 0.0, 0.0)];
              *
              *     左旋转45°缩小到最小,然后再从小到大推出.
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.50, -0.50, 0.50)];
              *
              *     旋转180°缩小到最小,然后再从小到大推出.
              *     animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.1, 0.2, 0.2)];
              */
               
             animation.duration = 0.45;
             animation.repeatCount = 1;
             [view.layer addAnimation:animation forKey:nil];
               
         }
                         completion:^(BOOL finished)
         {
             [UIView animateWithDuration:0.35f animations:^
              {
                  view.transform = CGAffineTransformMakeScale(1.0, 1.0);
              }];
         }];
    }
      
    /** CABasicAnimation
     *
     *  @see https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreAnimation_guide/Articles/KVCAdditions.html
     *
     *  @brief                      便利构造函数 animationWithKeyPath: KeyPath需要一个字符串类型的参数,实际上是一个
     *                              键-值编码协议的扩展,参数必须是CALayer的某一项属性,你的代码会对应的去改变该属性的效果
     *                              具体可以填写什么请参考上面的URL,切勿乱填!
     *                              例如这里填写的是 @"transform.rotation.z" 意思就是围绕z轴旋转,旋转的单位是弧度.
     *                              这个动画的效果是把view旋转到最小,再旋转回来.
     *                              你也可以填写@"opacity" 去修改透明度...以此类推.修改layer的属性,可以用这个类.
     *
     *  @param toValue              动画结束的值.CABasicAnimation自己只有三个属性(都很重要)(其他属性是继承来的),分别为:
     *                              fromValue(开始值), toValue(结束值), byValue(偏移值),
     !                              这三个属性最多只能同时设置两个;
     *                              他们之间的关系如下:
     *                              如果同时设置了fromValue和toValue,那么动画就会从fromValue过渡到toValue;
     *                              如果同时设置了fromValue和byValue,那么动画就会从fromValue过渡到fromValue + byValue;
     *                              如果同时设置了byValue  和toValue,那么动画就会从toValue - byValue过渡到toValue;
     *
     *                              如果只设置了fromValue,那么动画就会从fromValue过渡到当前的value;
     *                              如果只设置了toValue  ,那么动画就会从当前的value过渡到toValue;
     *                              如果只设置了byValue  ,那么动画就会从从当前的value过渡到当前value + byValue.
     *
     *                              可以这么理解,当你设置了三个中的一个或多个,系统就会根据以上规则使用插值算法计算出一个时间差并
     *                              同时开启一个Timer.Timer的间隔也就是这个时间差,通过这个Timer去不停地刷新keyPath的值.
     !                              而实际上,keyPath的值(layer的属性)在动画运行这一过程中,是没有任何变化的,它只是调用了GPU去
     *                              完成这些显示效果而已.
     *                              在这个动画里,是设置了要旋转到的弧度,根据以上规则,动画将会从它当前的弧度专旋转到我设置的弧度.
     *
     *  @param duration             动画持续时间
     *
     *  @param timingFunction       动画起点和终点之间的插值计算,也就是说它决定了动画运行的节奏,是快还是慢,还是先快后慢...
     */
      
    /** CAAnimationGroup
     *
     *  @brief                      顾名思义,这是一个动画组,它允许多个动画组合在一起并行显示.比如这里设置了两个动画,
     *                              把他们加在动画组里,一起显示.例如你有几个动画,在动画执行的过程中需要同时修改动画的某些属性,
     *                              这时候就可以使用CAAnimationGroup.
     *
     *  @param duration             动画持续时间,值得一提的是,如果添加到group里的子动画不设置此属性,group里的duration会统一
     *                              设置动画(包括子动画)的duration属性;但是如果子动画设置了duration属性,那么group的duration属性
     *                              的值不应该小于每个子动画中duration属性的值,否则会造成子动画显示不全就停止了动画.
     *
     *  @param autoreverses         动画完成后自动重新开始,默认为NO.
     *
     *  @param repeatCount          动画重复次数,默认为0.
     *
     *  @param animations           动画组(数组类型),把需要同时运行的动画加到这个数组里.
     *
     *  @note  addAnimation:forKey  这个方法的forKey参数是一个字符串,这个字符串可以随意设置.
     *
     *  @note                       如果你需要在动画group执行结束后保存动画效果的话,设置 fillMode 属性,并且把
     *                              removedOnCompletion 设置为NO;
     */
      
    + (void)animationRotateAndScaleDownUp:(UIView *)view
    {
        CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
     rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];
     rotationAnimation.duration = 0.35f;
     rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
          
     CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
     scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];
     scaleAnimation.duration = 0.35f;
     scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
       
     CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
     animationGroup.duration = 0.35f;
     animationGroup.autoreverses = YES;
     animationGroup.repeatCount = 1;
     animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil];
     [view.layer addAnimation:animationGroup forKey:@"animationGroup"];
    }
      
      
      
    #pragma mark - Private API
      
    + (void)animationFlipFromTop:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"oglFlip"];
        [animation setSubtype:@"fromTop"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationFlipFromBottom:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"oglFlip"];
        [animation setSubtype:@"fromBottom"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationCubeFromLeft:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromLeft"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationCubeFromRight:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromRight"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationCubeFromTop:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromTop"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationCubeFromBottom:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cube"];
        [animation setSubtype:@"fromBottom"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationSuckEffect:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"suckEffect"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationRippleEffect:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"rippleEffect"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationCameraOpen:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cameraIrisHollowOpen"];
        [animation setSubtype:@"fromRight"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
      
    + (void)animationCameraClose:(UIView *)view
    {
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.35f];
        [animation setFillMode:kCAFillModeForwards];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setType:@"cameraIrisHollowClose"];
        [animation setSubtype:@"fromRight"];
          
        [view.layer addAnimation:animation forKey:nil];
    }
    @end

    转载于:https://www.cnblogs.com/sunshinesl/p/4748501.html

    展开全文
  • ios 动画

    2013-09-09 17:10:38
    ios 2012-03-21 13:34 4689人阅读 评论(2) 收藏 举报 animationtransitionframeworksapi 需要在frameworks中添加QuartzCore.framework 在接口程序中加上头文件 #import /*好多动画效果*/  

    CATransition 的初级应用及type属性

    分类: ios 4689人阅读 评论(2) 收藏 举报

    需要在frameworks中添加QuartzCore.framework

    在接口程序中加上头文件   #import <QuartzCore/QuartzCore.h>

    /*好多动画效果*/

        CATransition *transition = [CATransition animation];
        transition.duration = 1.0f;         
    /* 间隔时间*/
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; /* 动画的开始与结束的快慢*/
        transition.type = @"rippleEffect";
    /* 各种动画效果*/

    //@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"

        transition.subtype = kCATransitionFromRight;   /* 动画方向*/
        transition.delegate = self;
        [navigationController.view.layer
    /* 在想添加CA动画的VIEW的层上添加此代码*/addAnimation:transition forKey:nil];

    //另外加一句,transition在申请时用的是+方法,所以不需要自己进行release ,在层上添加后不要认为retainCount已经+1,就还要release

    //实际上CATransition类中还有一个属性是removedOnCompletion,是此动画执行完后会自动remove,默认值为true



    CATransition的type属性

    这里使用了setType与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下:

    1. <STRONG>setType<SPAN style="COLOR: #339933">:</SPAN>可以返回四种类型:</STRONG>  
    2. kCATransitionFade淡出  
    3. kCATransitionMoveIn覆盖原图  
    4. kCATransitionPush推出  
    5. kCATransitionReveal底部显出来  
    6. <STRONG>setSubtype<SPAN style="COLOR: #339933">:</SPAN>也可以有四种类型:</STRONG>  
    7. kCATransitionFromRight;  
    8. kCATransitionFromLeft<SPAN style="COLOR: #009900">(</SPAN>默认值<SPAN style="COLOR: #009900">)</SPAN>  
    9. kCATransitionFromTop;  
    10. kCATransitionFromBottom  

    还有一种设置动画类型的方法,不用setSubtype,只用setType

    1. animation.type=@"pageCurl";  
    1. pageCurl   向上翻一页  
    2. pageUnCurl 向下翻一页  
    3. rippleEffect 滴水效果  
    4. suckEffect 收缩效果,如一块布被抽走  
    5. cube 立方体效果  
    6. oglFlip 上下翻转效果  


       示例

    CATransition *animation=[CATransition animation];
     animation.delegate=self;
     animation.duration=1.0f;

    animation.timingFunction=UIViewAnimationCurveEaseInOut;

    animation.type=kCATransitionMoveIn;
    animation.subtype=kCATransitionFromTop;
     [myView.layer addAnimation:animation forKey:@"move in"];

    展开全文
  • 30个iOS常用动画

    2015-09-30 14:39:04
    30多个iOS常用动画,带详细注释 // // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All rights reserved. // import   ...
  • iOS 动画

    2017-02-09 13:49:01
    //  // CoreAnimationEffect.h  // CoreAnimationEffect ...// Created by VincentXue on 13-1-19.  // Copyright (c) 2013年 VincentXue. All rights reserved.  //    #import    /**
  • iOS动画切换

    2015-08-07 16:32:49
    转载的一片关于动画的文章,很全 CALayer下的CATransition 一.封装动画方法 1.用CATransition实现动画的封装方法如下,每句代码是何意思,请看注释之。 ...13 14 15 16
  • IOS 30多个iOS常用动画,带详细注释 // // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All rights...
  • TFYProgressSwiftHUD Swift版的多动画提示框,最低支持iOS 13 系统以上。 可以 pod 'TFYProgressSwiftHUD' 安装使用时刻有更新版本 有需求的可以下载demo 查看。谢谢
  • 30多种iOS常用动画

    2015-01-13 10:08:16
    转自:...// // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All right
  • IOS 动画

    2014-05-14 12:04:07
    // // CoreAnimationEffect.h // CoreAnimationEffect ...// Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All rights reserved. //   #import   /**
  • 和前一章类似,交互式转场动画仅仅是代理方法的不同。通过手势滑动设置动画的进度。 我们来创建一个动画构造器,需要用到苹果内置的动画构造类UIPercentDrivenInteractiveTransition(这是一个类,不是协议,继承时...
  • iOS 常用动画集锦

    2014-07-22 08:34:34
    // // CoreAnimationEffect.h // CoreAnimationEffect ...// Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All rights reserved. // #import /** ! 导入QuartzCore.framework *
  • 30多个iOS常用动画,带详细注释 // // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright (c) 2013年 VincentXue. All rights reserved. // import ...
  • 30多个iOS常用动画,带详细注释 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 ...

空空如也

空空如也

1 2 3 4 5 ... 15
收藏数 291
精华内容 116
关键字:

ios13动画