• CAKeyframeAnimation常用属性 and 如何抖动view


     1     // 创建帧动画对象(缩放bounds,平移position,旋转transform)
     2     CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
     3     // values是用来存放要执行的每一帧动画
     4     NSValue *value1 = [NSValue valueWithCGPoint:CGPointZero];
     5     NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(300, 0)];
     6     NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(300, 300)];
     7     NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(0, 300)];
     8     NSValue *value5 = [NSValue valueWithCGPoint:CGPointZero];
     9     anim.values = @[value1,value2,value3,value4,value5];
    10     
    11     // 设置每一帧执行的时间(注意:里面的每一个值取值范围是0到1,后面的值必须大于前面的值)
    12     // 每一帧执行的时间 = (后一个时间点 - 前一个时间点) * 动画执行总时间
    13     anim.keyTimes = @[@(0),@(0.2),@(0.5),@(0.7),@(1)];
    14     
    15     // 设置动画执行节奏(慢进满出,中间快)
    16     //    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    17     // 设置动画时间
    18     anim.duration = 2.0f;
    19     
    20     // 设置保存动画执行状态
    21     anim.removedOnCompletion = NO;
    22     anim.fillMode = kCAFillModeForwards;
    23     // 把动画添加到图层上面
    24     [self.redView.layer addAnimation:anim forKey:nil];

    抖动图片


    将角度转换弧度

       #define angleRadian(angle) ((angle)* M_PI/ 180.0)


    1
    if ([self.iconView.layer animationForKey:@"animation"]){//如果动画进行中 2 // 停止动画 3 [self.iconView.layer removeAnimationForKey:@"animation"]; 4 return; 5 } 6 // 创建动画对象 7 CAKeyframeAnimation *keyframe = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"]; 8 9 keyframe.values = @[@(-angleRadian(3)),@(angleRadian(3)), @(-angleRadian(3))]; 10 11 // 设置代理 12 keyframe.delegate = self; 13 14 // 设置动画时间 15 keyframe.duration = 0.2f; 16 // 设置动画执行次数 17 keyframe.repeatCount = MAXFLOAT; 18 19 // 把动画添加到头像上 20 [self.iconView.layer addAnimation:keyframe forKey:@"animation"];

    #pragma mark - 动画代理方法

    - (void)animationDidStart:(CAAnimation *)anim {

        NSLog(@"animationDidStart");

    }

     

    - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

        NSLog(@"animationDidStop");

    }

  • 相关阅读:
    微信公众号教程(5)自动回复操作案例
    微信公众号教程(4)微信公众平台编辑模式介绍
    微信公众号教程(3)微信公众平台群发消息
    微信公众号教程(2)微信公众平台后台介绍
    微信公众号教程(1)微信公众账号注册、设置、登陆
    二级c程序设计题(2)
    二级c程序设计题(1)
    C++经典编程题#6:分配病房
    C++经典编程题#5:寻找下标
    python-----面向对象三大特性
  • 原文地址:https://www.cnblogs.com/neilHoIOS/p/4628462.html
Copyright © 2020-2023  润新知