Last active
September 29, 2015 19:36
-
-
Save jungchris/832f3aa8bd51023215e5 to your computer and use it in GitHub Desktop.
Control Rotation and Allow for Only One View
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
// this delegate is executed before each rotation. Here we allow only one view to go to landscape | |
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window | |
{ | |
// get the array of VCs from the nav controller | |
UINavigationController *navControl = (UINavigationController*)self.window.rootViewController; | |
NSArray *controllerArray = navControl.viewControllers; | |
NSUInteger controllerCount = [controllerArray count]; | |
// safety check, make sure we have at least one view controller on the stack | |
if (controllerCount > 0) { | |
// get the last view controller on the stack | |
UIViewController *lastController = [controllerArray objectAtIndex:(controllerCount-1)]; | |
// make sure it matches the class we want to allow rotation | |
if ([lastController isKindOfClass:[CCJVideoPlayerVC class]]) | |
{ | |
// get a local copy so we can check it's status | |
CCJVideoPlayerVC *lvtvc = (CCJVideoPlayerVC*)lastController; | |
if (lvtvc.isPresented) { | |
// NSLog(@"The returned mask is UIInterfaceOrientationMaskAll"); | |
return UIInterfaceOrientationMaskAll; | |
} else { | |
// NSLog(@"The returned mask is UIInterfaceOrientationMaskPortrait"); | |
return UIInterfaceOrientationMaskPortrait; | |
} | |
} else { | |
// all other views | |
return UIInterfaceOrientationMaskPortrait; | |
} | |
} else { | |
NSLog(@"CATCH: no view controllers in AppDelegate:supportedInterfaceOrientationsForWindow"); | |
return UIInterfaceOrientationMaskPortrait; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment