iOS 图标抖动动画

抖动动画如图

实现上面效果代码如下:

#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"];

你可能感兴趣的:(iOS 图标抖动动画)