跟iPhone手机图标类似的控件抖动

谷梁向荣
2023-12-01

- (void)shakeImage:(UIimageView *)image{
    //创建动画对象,绕Z轴旋转
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    
    //设置属性,周期时长
    [animation setDuration:0.15];
    
    //抖动角度
    animation.fromValue = @(-M_1_PI/10);
    animation.toValue = @(M_1_PI/10);
    //重复次数,无限大
    animation.repeatCount = HUGE_VAL;
    //恢复原样
    animation.autoreverses = YES;
    //锚点设置为图片中心,绕中心抖动
    image.layer.anchorPoint = CGPointMake(0.5, 0.5);

    [image.layer addAnimation:animation forKey:@"rotation"];
}

 类似资料: