iOS 图标抖动动画

2019-01-17  本文已影响5人  Sweet丶
抖动动画如图

实现上面效果代码如下:

#define Angle2Radian(angle) ((angle) / 180.0 * M_PI)
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];

    anim.values = @[@(Angle2Radian(-3)), @(Angle2Radian(3)), @(Angle2Radian(-3))];
    anim.duration = .2;
    anim.repeatCount = MAXFLOAT;
    
    // removedOnCompletion和fillMode一般是配合起来用的
    // 添加layer层的核心动画都会加上
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;

    [self.imgV.layer addAnimation:anim forKey:@"SHAKE"];

移除动画代码:

[self.imgV.layer removeAnimationForKey:@"SHAKE"];
上一篇下一篇

猜你喜欢

热点阅读