zoukankan      html  css  js  c++  java
  • iOS 核心动画Core Animation

    Core Animation

    基本3种动画:基本动画CABasicAnimation、  关键帧动画CAKeyframeAnimation、 转场动画CATransition

    还有就是动画组:CAAnimationGroup

    一、基本动画CABasicAnimation的使用:

    CABasicAnimation * animation = [CABasicAnimation animation];
        //相应属性的值 如:transform.scale(缩放)、 transform.rotation.z(z轴,做旋转的时候)。。。
        animation.keyPath = keyPath;
        animation.toValue = toValue;//如改变缩放结束时的值 toValue = @0.5 、旋转角度 toValue = @(M_PI)
        animation.repeatCount = MAXFLOAT;
        // 设置动画完成的时候不要移除动画
        animation.removedOnCompletion = NO;
        //设置动画执行完成要保持最新的效果
        animation.fillMode = kCAFillModeForwards;
        /*
        duration    动画时长
        repeatCount    动画循环次数
        repeatDuration    动画时间
        timingFunction    动画的速度变化
        fromValue    所改变属性的起始值
        toValue    所改变属性的结束时的值
         */
    //添加到对应的view的layer层上
    [view.layer addAnimation:animation forKey:nil];

    二、关键帧动画CAKeyframeAnimation

    1、模拟iOS系统删除应用晃动的动画

    CAKeyframeAnimation * rotation = [CAKeyframeAnimation animation];
        //相应属性
        rotation.keyPath = @"transform.rotation";
        //每个关键帧 改变属性的值
        rotation.values = @[@(TORADION(-5)),@(TORADION(5)),@(TORADION(-5))];
        rotation.repeatCount = MAXFLOAT;
       //添加到相应的view的layer上
        [view.layer addAnimation:rotation forKey:nil];

    2、运动轨迹

    //创建一个路径  或者得到一个路径
        UIBezierPath * bezierPath = [UIBezierPath bezierPath];
        [bezierPath moveToPoint:CGPointMake(0, 400)];
        [bezierPath addLineToPoint:CGPointMake(50, 300)];
        [bezierPath addLineToPoint:CGPointMake(100, 400)];
        [bezierPath addLineToPoint:CGPointMake(200, 300)];
        [bezierPath addLineToPoint:CGPointMake(250, 400)];
        [bezierPath addLineToPoint:CGPointMake(300, 250)];
        [bezierPath addLineToPoint:CGPointMake(330, 350)];
        [bezierPath addLineToPoint:CGPointMake(380, 300)];
        [bezierPath addLineToPoint:CGPointMake(450, 400)];
        
        CAKeyframeAnimation * position = [CAKeyframeAnimation animation];
        position.keyPath = @"position";
        //动画移动路径
        position.path = bezierPath.CGPath;
        position.repeatCount = MAXFLOAT;
        position.duration = 3;
        //添加到对应的view的layer上
        [view.layer addAnimation:rotation forKey:nil];

    三、转场动画CATransition 

    转场动画一定要在转场的时候使用才有效,如:改变UIImageView的图片

    //改变ImageView.image的时候(转场)
        _imageView.image = [UIImage imageNamed:img];
        CATransition *atransition = [CATransition animation];
        //类型
        atransition.type = @"rippleEffect";
        atransition.duration = 1;
       //添加到_imageView的layer上 [_imageView.layer addAnimation:atransition forKey:nil];
    /* 类型 1.#define定义的常量 kCATransitionFade 交叉淡化过渡 kCATransitionMoveIn 新视图移到旧视图上面 kCATransitionPush 新视图把旧视图推出去 kCATransitionReveal 将旧视图移开,显示下面的新视图 2.用字符串表示 pageCurl 向上翻一页 pageUnCurl 向下翻一页 rippleEffect 滴水效果 suckEffect 收缩效果,如一块布被抽走 cube 立方体效果 oglFlip 上下翻转效果 */

    四、动画组CAAnimationGroup

    这个很简单,就是把几个动画放到一个数组中去执行动画

    // 同时缩放,平移,旋转
        //创建一个动画组
        CAAnimationGroup *group = [CAAnimationGroup animation];
        
        //缩放
        CABasicAnimation *scale = [CABasicAnimation animation];
        scale.keyPath = @"transform.scale";
        scale.toValue = @0.5;
        
        //旋转
        CABasicAnimation *rotation = [CABasicAnimation animation];
        rotation.keyPath = @"transform.rotation";
        rotation.toValue = @(arc4random_uniform(M_PI));
        
        //平移
        CABasicAnimation *position = [CABasicAnimation animation];
        position.keyPath = @"position";
        position.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(200), arc4random_uniform(200))];
        
        //添加到动画组
        group.animations = @[scale,rotation,position];
        
        //添加到相应的view的layer上
        [view.layer addAnimation:group forKey:nil];

    简单介绍    不好  勿喷。

  • 相关阅读:
    mysql-5.7(centos-6.9环境)源码安装
    Oracle 11g 体系结构思维导图
    my.cnf 配置文件参数优化
    职业生涯规划
    技能栈规划图
    操作文档 Oracle 11g (CentOS7.2环境) 静默安装
    oracle 静默安装响应文件 参数说明
    oracle em企业管理器的安装、配置及相关问题
    大数据第51天—Mysql练习题12道之六-今年10月份第一次购买商品的金额-杨大伟
    大数据第50天—Mysql练习题12道之五-活跃用户的总数-杨大伟
  • 原文地址:https://www.cnblogs.com/qq9070/p/6786044.html
Copyright © 2011-2022 走看看