Skip to content

Instantly share code, notes, and snippets.

@nonstriater
Forked from brunojppb/AppDelegate.m
Created March 20, 2017 06:52
Show Gist options
  • Save nonstriater/d1e14a3567118b24bfbe8b478b26919f to your computer and use it in GitHub Desktop.
Save nonstriater/d1e14a3567118b24bfbe8b478b26919f to your computer and use it in GitHub Desktop.
Allow landscape mode in specific ViewControllers
/* 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