Created
May 15, 2018 09:05
-
-
Save zummenix/dfbe52b9ce390d44aff9fa68c4b0fa94 to your computer and use it in GitHub Desktop.
Finds rotation difference between two interface orientations
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
/** | |
Finds rotation difference between two interface orientations. | |
For example, difference between Portrait and PortraitUpsideDown is 2 (rotate by 180 degrees), | |
defference between Portrait and LandscapeLeft is 1 (rotate by 90 degrees). | |
@param source source interface orientation | |
@param destination destination interface orientation | |
@return rotation difference between orientations in range [0, 3]. | |
*/ | |
NSInteger rotationDifference(UIInterfaceOrientation source, UIInterfaceOrientation destination) { | |
NSArray *matrix = @[ | |
@(UIInterfaceOrientationPortrait), | |
@(UIInterfaceOrientationLandscapeLeft), | |
@(UIInterfaceOrientationPortraitUpsideDown), | |
@(UIInterfaceOrientationLandscapeRight), | |
]; | |
NSInteger sourceIndex = [matrix indexOfObject:@(source)]; | |
NSInteger destinationIndex = [matrix indexOfObject:@(destination)]; | |
if (sourceIndex == NSNotFound || destinationIndex == NSNotFound) { | |
return 0; | |
} else { | |
return ABS(sourceIndex - destinationIndex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment