Skip to content

Instantly share code, notes, and snippets.

@bocato
Created June 30, 2016 13:20
Show Gist options
  • Save bocato/641098d927b64d102781959ac999d27e to your computer and use it in GitHub Desktop.
Save bocato/641098d927b64d102781959ac999d27e to your computer and use it in GitHub Desktop.
Hack to control screen orientation on iPad/iPhone for a specific inner ViewController
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([self.currentViewController isEqual:self.viewControllerYouDontWantToRotate])
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskAll;
}
}
- (BOOL)shouldAutorotate
{
if ([self.currentViewController isEqual:self.viewControllerYouDontWantToRotate])
{
return NO;
}
else
{
return YES;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (void)rotateToLandscape{
NSNumber *valueLandscape = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:valueLandscape forKey:@"orientation"];
}
- (void)rotateToPortrait{
NSNumber *valuePortrait = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:valuePortrait forKey:@"orientation"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment