Skip to content

Instantly share code, notes, and snippets.

@jungchris
Last active September 29, 2015 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jungchris/832f3aa8bd51023215e5 to your computer and use it in GitHub Desktop.
Save jungchris/832f3aa8bd51023215e5 to your computer and use it in GitHub Desktop.
Control Rotation and Allow for Only One View
// 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