Rotate UIImageView clockwise

后端 未结 4 1787
再見小時候
再見小時候 2021-02-03 11:48

This should be simple, but I\'m having trouble rotating a UIImageView a full 360 degrees, repeated forever.

[UIView animateWithDuration:0.5 delay:0          


        
4条回答
  •  梦如初夏
    2021-02-03 12:20

    Christoph is already going the correct way, but there is a far better way to keep it spinning without reinvoke it in the animation delegates every time it ends. This is simply wrong.

    Just set the repeatCount property of your animation to HUGE_VALF.

    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = @0.0f;
    animation.toValue = @(2*M_PI);
    animation.duration = 0.5f;             // this might be too fast
    animation.repeatCount = HUGE_VALF;     // HUGE_VALF is defined in math.h so import it
    [self.reloadButton.imageView.layer addAnimation:animation forKey:@"rotation"];
    

    As stated in the documentation, this will cause the animation to repeat forever.

提交回复
热议问题