iOS实现旋转动画

   CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];//rotation.z
    //默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
    animation.toValue =   [NSNumber numberWithFloat: M_PI *2];
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    animation.duration = 2;
    animation.autoreverses = NO;
    animation.cumulative = NO;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = FLT_MAX; //如果这里想设置成一直自旋转,可以设置为FLT_MAX,
    [self.animationImgView.layer addAnimation:animation forKey:@"animation"];
    [self.animationImgView startAnimating];

猜你喜欢

转载自blog.csdn.net/LIUXIAOXIAOBO/article/details/131253929