[英]How to rotate image 360 degrees endlessly using iPhone SDK?
I want to rotate image 360 degrees endlessly using iPhone SDK? 我想使用iPhone SDK将图像无限旋转360度吗?
How can this be done? 如何才能做到这一点?
Thanks! 谢谢!
-(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];
}
Try using this, it works. 尝试使用它,它起作用。
Assuming you are displaying the image in a UIImageView
, you can rotate the view's local coordinate system (see here ) and use NSTimer
to increase the rotation periodically (see here ). 假设您正在
UIImageView
中显示图像,则可以旋转视图的局部坐标系(请参阅此处 ),并使用NSTimer
定期增加旋转(请参见此处 )。
(I would use OpenGL for this, but that's just a personal preference and is probably overkill for your situation.) (我会为此使用OpenGL,但这只是个人喜好,可能对您的情况有些过分。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.