Skip to content

Instantly share code, notes, and snippets.

@jamztang
Last active October 5, 2015 18:29
Show Gist options
  • Save jamztang/2853792 to your computer and use it in GitHub Desktop.
Save jamztang/2853792 to your computer and use it in GitHub Desktop.
Handy marco to return supported UIInterfaceOrientation for your View Controllers
// Created by Jamz Tang 2012-06-02
// http://ioscodesnippet.com/post/24203288551/quickly-switch-supported-uiinterfaceorientation-for
// Convert UIInterfaceOrientation to NSString, so we can compare it
static inline NSString *NSStringFromUIInterfaceOrientation(UIInterfaceOrientation orientation) {
switch (orientation) {
case UIInterfaceOrientationPortrait: return @"UIInterfaceOrientationPortrait";
case UIInterfaceOrientationPortraitUpsideDown: return @"UIInterfaceOrientationPortraitUpsideDown";
case UIInterfaceOrientationLandscapeLeft: return @"UIInterfaceOrientationLandscapeLeft";
case UIInterfaceOrientationLandscapeRight: return @"UIInterfaceOrientationLandscapeRight";
}
return @"Unexpected";
}
// Check info.plist for the UISupportedInterfaceOrientations key, it returns an array of NSString
#define UIInterfaceOrientationIsSupportedOrientation(orientation) ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"] indexOfObject:NSStringFromUIInterfaceOrientation(orientation)] != NSNotFound)
@Zammy
Copy link

Zammy commented Nov 29, 2013

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment