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

    Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统

    Quartz 2D能完成的工作

    绘制图形 : 线条三角形矩形圆弧等

    绘制文字

    绘制生成图片(图像)

    读取生成PDF

    截图裁剪图片

    自定义UI控件

    … …

    1、CABasicAnimation(基本动画)
     
    1.1->创建动画对象

    CABasicAnimation *anim = [CABasicAnimation animation];

    1.2->设置动画对象

    keyPath决定了执行怎样的动画, 调整哪个属性来执行动画

    anim.keyPath = @"transform.rotation";

    anim.keyPath = @“bounds";

    anim.keyPath = @“transform";

    anim.keyPath = @“transform.translation.x”;

    //起始状态,如果不设置则默认从图层所在位置开始动画

    anim.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];

    //结束状态

    anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];

    byValue : 增加多少值  toValue:最终变成值的多少

    //动画时长

    anim.duration = 2.0;

    //重复次数

    anim.repeatCount = MAXFLOAT;

    1.3 ->让图层保持动画执行完毕后的状态

    // 动画执行完毕后不要删除动画

    anim.removedOnCompletion = NO;

    // 保持最新的状态

    anim.fillMode = kCAFillModeForwards;

    1.4 ->添加动画到图层

    [self.layer addAnimation:anim forKey:nil];(后面的这个key值是可以指定某一个动画的)

    2、CAKeyframeAnimation(关键帧动画)

    2.1->创建动画对象

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

    2.2->设置动画对象

    keyPath决定了执行怎样的动画, 调整哪个属性来执行动画

    anim.keyPath = @"transform.rotation";

    anim.keyPath = @“bounds";

    anim.keyPath = @“transform";

    anim.keyPath = @“transform.translation.x”;

    //动画时长

    anim.duration = 2.0;

    //重复次数

    anim.repeatCount = MAXFLOAT;

    // 设置动画的执行节奏

    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    //设置动画的执行路径(也可以设置关键帧数组)

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathAddEllipseInRect(path, NULL, CGRectMake(100, 100, 200, 200));

     anim.path = path;

    //注意:C语言中如果使用了create方法创建的,都要释放,不然会有内存泄漏

     CGPathRelease(path);

    //设置关键帧数组(也可以设置动画的执行路径)

     anim.keyPath = @"position";

     NSValue *v1 = [NSValue valueWithCGPoint:CGPointZero];

      NSValue *v2 = [NSValue valueWithCGPoint:CGPointMake(100, 0)];

      NSValue *v3 = [NSValue valueWithCGPoint:CGPointMake(100, 200)];

      NSValue *v4 = [NSValue valueWithCGPoint:CGPointMake(0, 200)];

      anim.values = @[v1, v2, v3, v4];

    2.3 ->让图层保持动画执行完毕后的状态

    // 动画执行完毕后不要删除动画

    anim.removedOnCompletion = NO;

    // 保持最新的状态

    anim.fillMode = kCAFillModeForwards;

    2.4 ->添加动画到图层

    [self.layer addAnimation:anim forKey:nil];(后面的这个key值是可以指定某一个动画的)

    2.5 ->移除动画(如果要移除一个动画,那么这个动画一定要设置Key值)

    [self.iconView.layer removeAnimationForKey:@“shake"];

    3、CATransition(转场动画)


    3.1->创建动画对象

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

    3.2->设置动画对象

    anim.type = @“pageUnCurl";

    anim.subtype = kCATransitionFromLeft;

     

    anim.startProgress = 0.0;

    anim.endProgress = 0.5;

    3.3 ->添加动画到图层

    [self.layer addAnimation:anim forKey:nil];

    4、CAAnimationGroup(动画组)
     
       // 4.1.创建旋转动画对象

        CABasicAnimation *rotate = [CABasicAnimation animation];

        rotate.keyPath = @"transform.rotation";

        rotate.toValue = @(M_PI);    

       // 4.2.创建缩放动画对象

        CABasicAnimation *scale = [CABasicAnimation animation];

        scale.keyPath = @"transform.scale";

        scale.toValue = @(0.0);

        // 4.3.平移动画

        CABasicAnimation *move = [CABasicAnimation animation];

        move.keyPath = @"transform.translation";

        move.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];

        // 4.4.将所有的动画添加到动画组中

        CAAnimationGroup *group = [CAAnimationGroup animation];

        group.animations = @[rotate, scale, move];

        group.duration = 2.0;

        group.removedOnCompletion = NO;

        group.fillMode = kCAFillModeForwards;

        // 4.5.把动画组添加到图层中

        [self.myvie.layer addAnimation:group forKey:nil];

    5、其它动画

    1 -> //好像只适用在iPad上,也是类似于转场动画(?)
    [UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionCurlUp animations:nil completion:nil];
    2->[UIView beginAnimations:nil context:nil];

    self.myview.center = CGPointMake(200, 300);

     [UIView commitAnimations];

    3 -> [UIView animateWithDuration:1.0 animations:^{

            self.myview.center = CGPointMake(200, 300);

        } completion:^(BOOL finished) {

     }];

     
  • 相关阅读:
    【网摘】Data Warehousing and BI Introduction
    【网摘】OLAP and Business Intelligence (ROLAP vs. MOLAP vs. HOLAP)
    [Oracle Issues]Wrong Password for User for Host Credentials in EM
    [Oracle Utility] Adrian Billington’s data_dump
    [Oracle Data Cartridge Interface] UserDefined Aggregation Functions
    【网摘】MVP (Passive View and Supervising Controller)
    SQL Techniques – Columns to Rows, Rows to Columns
    [Oracle Mgmt] Query Archivelog Mode, Change Archivelog Dest, etc.
    [Oracle SQL]Greatest and Least
    [Oracle 9i] Case Expression and Case Statement in 9i
  • 原文地址:https://www.cnblogs.com/bluceZ/p/3938385.html
Copyright © 2011-2022 走看看