我想使用iPhone SDK无休止地旋转图像360度?
如何做到这一点?
谢谢!
答案 0 :(得分:4)
-(void)startAnimationWithRevolutions:(float)revPerSecond forTime:(float)time
{
spinWheel.userInteractionEnabled = FALSE;
float totalRevolutions = revPerSecond * time;
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:time] forKey:kCATransactionAnimationDuration];
CABasicAnimation* spinAnimation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation"];
CGAffineTransform transform = spinWheel.transform;
float fromAngle = atan2(transform.b, transform.a);
float toAngle = fromAngle + (totalRevolutions*4*M_PI);
spinAnimation.fromValue = [NSNumber numberWithFloat:fromAngle];
spinAnimation.toValue = [NSNumber numberWithFloat:toAngle];
spinAnimation.repeatCount = 0;
spinAnimation.removedOnCompletion = NO;
spinAnimation.delegate = self;
spinAnimation.timingFunction = [CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseOut];
[spinWheel.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
[CATransaction commit];
}
尝试使用它,它可以工作。
答案 1 :(得分:0)
假设您正在UIImageView
中显示图像,您可以旋转视图的本地坐标系(请参阅here)并使用NSTimer
定期增加旋转(请参阅{{3 }})。
(我会使用OpenGL,但这只是个人偏好,对你的情况来说可能有些过分。)