-
-
Save jaminguy/7c51259808b84d424cb2 to your computer and use it in GitHub Desktop.
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)orientationByTransforming:(CGAffineTransform)transform fromOrientation:(UIInterfaceOrientation)c | |
{ | |
CGFloat angle = atan2f(transform.b, transform.a); | |
NSInteger multiplier = (NSInteger)roundf(angle / M_PI_2); | |
UIInterfaceOrientation orientation = self.interfaceOrientation; | |
if (multiplier < 0) { | |
// clockwise rotation | |
while (multiplier++ < 0) { | |
switch (orientation) { | |
case UIInterfaceOrientationPortrait: | |
orientation = UIInterfaceOrientationLandscapeLeft; | |
break; | |
case UIInterfaceOrientationLandscapeLeft: | |
orientation = UIInterfaceOrientationPortraitUpsideDown; | |
break; | |
case UIInterfaceOrientationPortraitUpsideDown: | |
orientation = UIInterfaceOrientationLandscapeRight; | |
break; | |
case UIInterfaceOrientationLandscapeRight: | |
orientation = UIInterfaceOrientationPortrait; | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
else if (multiplier > 0) { | |
// counter-clockwise rotation | |
while (multiplier-- > 0) { | |
switch (orientation) { | |
case UIInterfaceOrientationPortrait: | |
orientation = UIInterfaceOrientationLandscapeRight; | |
break; | |
case UIInterfaceOrientationLandscapeRight: | |
orientation = UIInterfaceOrientationPortraitUpsideDown; | |
break; | |
case UIInterfaceOrientationPortraitUpsideDown: | |
orientation = UIInterfaceOrientationLandscapeLeft; | |
break; | |
case UIInterfaceOrientationLandscapeLeft: | |
orientation = UIInterfaceOrientationPortrait; | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
return (UIInterfaceOrientation)orientation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment