Skip to content

Instantly share code, notes, and snippets.

@sergii-frost
Created October 28, 2014 14:01
Show Gist options
  • Save sergii-frost/d0b6a92c4fbac835bb28 to your computer and use it in GitHub Desktop.
Save sergii-frost/d0b6a92c4fbac835bb28 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