0

In my iPhone app, I have an image on the screen (UIImageView). I would like to spin it and increase the speed at a fixed rate. Basically I'm trying to create an effect where it starts to spin slowly and then increases the speed until the spinning is so fast so you cannot see the image anymore (only a fast animation).

I though of using an animation block and changing the rotation property of a transform, but I'm not sure how to control the speed.

4

1 回答 1

2

You're going to want to use an animation with the animation curve set to UIViewAnimationCurveEaseIn. Set the duration to a long interval, perhaps around 5 seconds. That should accomplish the effect you're looking for.


Sample code:

CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
spin.toValue = [NSNumber numberWithFloat:50*2*M_PI];
spin.duration = 5.f;
spin.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[imageView.layer addAnimation:spin forKey:@"spinningAnimation"];

If you wish to define your own animation curve, look into CAMediaTimingFunction's functionWithControlPoints:::: method.

于 2012-05-11T05:57:49.097 回答