Created
October 28, 2014 14:01
-
-
Save sergii-frost/d0b6a92c4fbac835bb28 to your computer and use it in GitHub Desktop.
iOS 8 fix to support old methods of device orientation changes
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
- (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