Skip to content

Instantly share code, notes, and snippets.

@hankbao
Created December 26, 2012 08:46
Show Gist options
  • Save hankbao/4378943 to your computer and use it in GitHub Desktop.
Save hankbao/4378943 to your computer and use it in GitHub Desktop.
Get a CGAffineTransform from a UIInterfaceOrientation
#define DEGREES_TO_RADIANS(degrees) (degrees * M_PI / 180)
static CGAffineTransform transformForOrientation(UIInterfaceOrientation orientation)
{
switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
case UIInterfaceOrientationLandscapeRight:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-90));
case UIInterfaceOrientationPortraitUpsideDown:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(180));
case UIInterfaceOrientationPortrait:
default:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment