iOS CAKeyframeAnimation 示例

view抖动示例:

//角度
#define Angle2Radian(angle) ((angle) / 180.0 * M_PI)

- (void)start
{
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    anim.keyPath = @"transform.rotation";
    
    anim.values = @[@(Angle2Radian(-15)),  @(Angle2Radian(15)), @(Angle2Radian(-15))];
    anim.duration = 0.25;
    // 动画的重复执行次数
    anim.repeatCount = MAXFLOAT;
    
    // 保持动画执行完毕后的状态
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    
    [self.iconView.layer addAnimation:anim forKey:@"shake"];
}

- (void)stop
{
    [self.iconView.layer removeAnimationForKey:@"shake"];
}




你可能感兴趣的:(iOS CAKeyframeAnimation 示例)