0

Possible Duplicate:
Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

I'm trying to create a game where pushing a button spins an dial image, having trouble with the rotation code. Goal is to spin the image from its current position by a % of 360, i.e .4 * 360, spin the image 144 degrees. Thanks Guys!

-(IBAction)spin:(id)sender
{

    float strenght = DEGREES_TO_RADIANS(.5 * 360);

    [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationCurveEaseOut animations:^
    {
        [spinner_iv setTransform:CGAffineTransformRotate([spinner_iv transform],strenght)];
    } 
    completion:^(BOOL finished) 
    {
        //done
    }];
}
Community
  • 1
  • 1

2 Answers2

1

UIView animations using CGAffineTransform take the 'shortest path', so if you request a clockwise rotation of 270 degrees, it will animate anticlockwise by 90 degrees.

You can get any number of spins if you instead rotate the view layer using CATransform3D - yes, use this even if you are rotating in 2D. See Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?

Community
  • 1
  • 1
Cowirrie
  • 7,218
  • 1
  • 29
  • 42
0

Converting degrees to radians is

Radians = Degrees * (PI/180)

Nick Bull
  • 4,276
  • 1
  • 18
  • 25