Skip to content

Instantly share code, notes, and snippets.

@Inferis
Last active September 19, 2020 21:02
Show Gist options
  • Select an option

  • Save Inferis/26ded6e1e8e625b3cd67 to your computer and use it in GitHub Desktop.

Select an option

Save Inferis/26ded6e1e8e625b3cd67 to your computer and use it in GitHub Desktop.

Revisions

  1. Tom Adriaenssen renamed this gist Apr 25, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Tom Adriaenssen created this gist Apr 25, 2015.
    51 changes: 51 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    - (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;
    }