Last active
November 17, 2017 05:54
-
-
Save coolio107/f843789e5225c1f6fc9b to your computer and use it in GitHub Desktop.
relativeInterfaceOrientationFromRotationAngle class extension for UIViewController
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
- (UIInterfaceOrientation)relativeInterfaceOrientationFromRotationAngle:(CGFloat)angle { | |
NSArray * conversionMatrix = @[ @(UIInterfaceOrientationPortrait), | |
@(UIInterfaceOrientationLandscapeRight), | |
@(UIInterfaceOrientationPortraitUpsideDown), | |
@(UIInterfaceOrientationMaskLandscapeLeft)]; | |
NSInteger oldIndex = [conversionMatrix indexOfObject:@(self.interfaceOrientation)]; | |
if (oldIndex == NSNotFound) | |
return UIInterfaceOrientationUnknown; | |
NSInteger newIndex = (oldIndex - (NSInteger)roundf(angle / M_PI_2)) % 4; | |
while (newIndex < 0) { | |
newIndex +=4; | |
} | |
return [conversionMatrix[newIndex] intValue]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift 4 conversion