tags:

views:

269

answers:

2

Any idea about how to spin image clockwise/anticlockwise on touch.

A: 

You'll want to use CoreAnimation for this; basically you'll need to apply an animation to the transform property of your image view. There are plenty of samples on Apple's developer page that show variations on this.

Ben Gottlieb
+1  A: 
#import <QuartzCore/QuartzCore.h> 

[UIView beginAnimations:@"RotationAnimation" context:nil];

CABasicAnimation *fullRotationAnimation;
fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotationAnimation .fromValue = [NSNumber numberWithFloat:0];
fullRotationAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotationAnimation.duration = 2;          // speed for the rotation. Smaller number is faster
fullRotationAnimation.repeatCount = 1e100f;  // number of times to spin. 1 = once
[myImage.layer addAnimation:fullRotationAnimation forKey:@"360"];

[UIView commitAnimations];
Canada Dev
Actually, I don't believe the begin / commit animations block for the UIView is necessary here, because you are explicitly animating the view's layer. You may also want to use "transform.rotation.z" as the keypath for the animation, to clearly specify what axis is being rotated about.
Brad Larson