Forked from felix-schwarz/UIViewControllerAttemptRotationToDeviceOrientationWorkaround.m
Last active
November 17, 2016 04:06
-
-
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…
This file contains hidden or 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
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