jamztang
6/1/2012 - 5:23 PM

Handy marco to return supported UIInterfaceOrientation for your View Controllers

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)