-
-
Save nonstriater/d1e14a3567118b24bfbe8b478b26919f to your computer and use it in GitHub Desktop.
Allow landscape mode in specific ViewControllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Allow Landscape mode for specific ViewControllers */ | |
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { | |
UIViewController* topVC = [self topViewControllerWith: self.window.rootViewController]; | |
if ([topVC respondsToSelector:@selector(canRotate)]) { | |
return UIInterfaceOrientationMaskAllButUpsideDown; | |
} | |
return UIInterfaceOrientationMaskPortrait; | |
} | |
/* get the top ViewController */ | |
- (UIViewController*) topViewControllerWith:(UIViewController *)rootViewController { | |
if (rootViewController == nil) { return nil; } | |
if ([rootViewController isKindOfClass: [UITabBarController class]]) { | |
return [self topViewControllerWith: ((UITabBarController*) rootViewController).selectedViewController]; | |
} | |
else if ([rootViewController isKindOfClass: [UINavigationController class]]) { | |
return [self topViewControllerWith: ((UINavigationController*) rootViewController).visibleViewController]; | |
} | |
else if (rootViewController.presentedViewController != nil) { | |
return [self topViewControllerWith: [rootViewController presentedViewController]]; | |
} | |
return rootViewController; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment