在开发过程中,我们有时需要实现图片无线旋转动画,下面给出示例代码:
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumbernumberWithFloat: M_PI *2.0 ];
rotationAnimation.duration =1;
rotationAnimation.cumulative =YES;
rotationAnimation.repeatCount =HUGE_VALF;
[_imageView .layeraddAnimation:rotationAnimation forKey:@"rotationAnimation"];
对repeatCount做个说明,官方文档是这么说的
May be fractional. If the repeatCount
is 0, it is ignored. Defaults to 0. If both repeatDuration and repeatCount are specified the behavior is undefined.
Setting this property to HUGE_VALF
will cause the animation to repeat forever.
有的会使用下面方法实现
rotation = rotation + 2*M_PI;
[UIView animateWithDuration:0.5 animations:^{
CGAffineTransform t = CGAffineTransformMakeRotation(rotation);
self.imageView.transform = t;
} completion:^(BOOL finished) {
[self useTouchIdButtonCLicked:nil];
}];
上述代码可以实现循环,但是中间会停顿一下,想必不是自己想要的效果