Skip to content

Instantly share code, notes, and snippets.

@revolc
Created March 28, 2014 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revolc/9830050 to your computer and use it in GitHub Desktop.
Save revolc/9830050 to your computer and use it in GitHub Desktop.
rotate a UIView
- (void)rotateView:(UIView*)view ToAngle:(CGFloat)angle animated:(BOOL)animated
{
NSParameterAssert(angle <= 360 && angle >= 0);
CGFloat radians = atan2f(view.transform.b, view.transform.a);
CGFloat degrees = radians * (180 / M_PI);
if ( fabs( degrees - angle ) < FLT_MIN) {
return;
}
CGFloat rotateRadians = angle * M_PI / 180;
animated = NO;
if (animated) {
[UIView animateWithDuration:0.3 animations:^{
view.transform = CGAffineTransformRotate(view.transform, rotateRadians);
}];
} else {
view.transform = CGAffineTransformRotate(view.transform, rotateRadians);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment