Skip to content

Instantly share code, notes, and snippets.

@sorted-bits
Created October 20, 2011 19:35
Show Gist options
  • Save sorted-bits/1302088 to your computer and use it in GitHub Desktop.
Save sorted-bits/1302088 to your computer and use it in GitHub Desktop.
shouldAllowRotateToInterfaceOrientation
+ (BOOL) shouldAllowRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
{
NSString* currentOrientation = @"";
switch (interfaceOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
currentOrientation = @"UIInterfaceOrientationLandscapeLeft";
break;
case UIInterfaceOrientationLandscapeRight:
currentOrientation = @"UIInterfaceOrientationLandscapeRight";
break;
case UIInterfaceOrientationPortrait:
currentOrientation = @"UIInterfaceOrientationPortrait";
break;
case UIInterfaceOrientationPortraitUpsideDown:
currentOrientation = @"UIInterfaceOrientationPortraitUpsideDown";
break;
}
NSString* supportedOrientationsKey = @"UISupportedInterfaceOrientations";
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
supportedOrientationsKey = @"UISupportedInterfaceOrientations~ipad";
NSArray* allowedOrientations = [[[NSBundle mainBundle] infoDictionary] objectForKey:supportedOrientationsKey];
for (NSString* allowedOrientation in allowedOrientations)
{
if ([allowedOrientation isEqualToString:currentOrientation])
return YES;
}
return NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment