Created
January 23, 2017 15:24
-
-
Save brunojppb/3f551b2a4b0b0215ec07e524bc1cfb09 to your computer and use it in GitHub Desktop.
Allow landscape mode in specific ViewControllers
This file contains hidden or 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