Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.