Skip to content

Instantly share code, notes, and snippets.

@edwardean
Forked from se-rg-os/iOS8ViewController.m
Created June 7, 2016 04:11
Show Gist options
  • Select an option

  • Save edwardean/a1a78b0e893ab79eb98008283f686b33 to your computer and use it in GitHub Desktop.

Select an option

Save edwardean/a1a78b0e893ab79eb98008283f686b33 to your computer and use it in GitHub Desktop.
iOS 8 fix to support old methods of device orientation changes
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
//The device has already rotated, that's why this method is being called.
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
//fixes orientation mismatch (between UIDeviceOrientation and UIInterfaceOrientation)
UIInterfaceOrientation toOrientation;
switch (deviceOrientation) {
case UIDeviceOrientationUnknown:
toOrientation = UIInterfaceOrientationUnknown;
break;
case UIDeviceOrientationPortraitUpsideDown:
toOrientation = UIInterfaceOrientationPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeLeft:
toOrientation = UIInterfaceOrientationLandscapeLeft;
break;
case UIDeviceOrientationLandscapeRight:
toOrientation = UIInterfaceOrientationLandscapeRight;
break;
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
case UIDeviceOrientationPortrait:
default:
toOrientation = UIInterfaceOrientationPortrait;
break;
}
UIInterfaceOrientation fromOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:toOrientation duration:0.0];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self willAnimateRotationToInterfaceOrientation:toOrientation duration:[context transitionDuration]];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self didRotateFromInterfaceOrientation:fromOrientation];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment