views:

79

answers:

1

Hi

I want to rotate a uiimageview by roughly 10 degrees left/right but have a smooth animation, rather than a sudden turn which I see using:

player.transform = CGAffineTransformMakeRotation(angle);

Any help appreciated, thanks.

A: 

I use some code like this to achieve a similar effect (though I rotate it by 360 degrees):

CABasicAnimation *rotate;
rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotate.fromValue = [NSNumber numberWithFloat:0];
rotate.toValue = [NSNumber numberWithFloat:deg2rad(10)];
rotate.duration = 0.25;
rotate.repeatCount = 1;
[self.view.layer addAnimation:rotate forKey:@"10"];

I use code very similar to this to spin an image view.

jer
Do I need to use a radian value for the angle of rotation?First time I've used it, says deg2rad not declared, what this? also that CABasicAnimation not declared.
Josh Kahane
yeah you need the radian value; deg2rad is just a placeholder to convert your 10 degrees into radians.
jer