views:

985

answers:

3

hi,

Can anyone tell me how to rotate an image in circular motion

+2  A: 

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;
Sam
A: 

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.

Brad Larson
Probably u r confused about rotation and revolution. The above question is about revolution.
Biranchi
+7  A: 

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"];
}
mahboudz
i'm getting an error, " rotations undeclared"
abhinav
rotations is a const. Replace it with the number of times you want the view to rotate in duration amount of time.
mahboudz