hi,
Can anyone tell me how to rotate an image in circular motion
hi,
Can anyone tell me how to rotate an image in circular motion
If you mean, "How do you make an image follow a circular path?", then the pseudocode would be:
image.x = circleCentre.x + cos(angle) * circleRadius;
image.y = circleCentre.y + sin(angle) * circleRadius;
angle += 5;
This question asks the same thing, although in different words. The answers in that question, as well as in this question should provide a way to animate a UIView (UIImageView is simply a subclass of this) about its center for 360 degrees or more.
You can rotate a view, by some number of radians, regardless of whether it is less than a full rotation or many multiples of a full rotation, without having to split the rotation into pieces. As an example, the following code will spin a view, once per second, for a specified number of seconds. You can easily modify it to spin a view by a certain number of rotations, or by some number of radians.
- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}