Skip to content

Instantly share code, notes, and snippets.

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 xingheng/de635eedb2fd107c28ecec93afe5938e to your computer and use it in GitHub Desktop.
Save xingheng/de635eedb2fd107c28ecec93afe5938e to your computer and use it in GitHub Desktop.
+[UIViewController attemptRotationToDeviceOrientation] does what it says on the tin: attempt to rotate to the device's orientation. It does, however, not rotate the view controller to match -[UIViewController supportedInterfaceOrientation] when the current device orientation is not supported by the view controller it polls. I whipped together th…
UIDeviceOrientation actualDeviceOrientation = [[UIDevice currentDevice] orientation];
BOOL changedDeviceOrientation = NO;
if ((self.supportedInterfaceOrientations & (UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight)) == 0)
{
if (UIScreen.mainScreen.bounds.size.width > UIScreen.mainScreen.bounds.size.height) // Device is in landscape orientation
{
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];
changedDeviceOrientation = YES;
}
}
[UIViewController attemptRotationToDeviceOrientation];
if (changedDeviceOrientation)
{
[[UIDevice currentDevice] setValue:@(actualDeviceOrientation) forKey:@"orientation"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment