Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Rotation Methods Deprecation - Backwards Compatibility

Tags:

ios

rotation

ios8

In iOS 8, the methods for interface rotation are deprecated. This includes:

  • willRotateToInterfaceOrientation:duration:
  • didRotateFromInterfaceOrientation:
  • willAnimateRotationToInterfaceOrientation:duration:

The replacement methods include:

  • willTransitionToTraitCollection:withTransitionCoordinator:
  • viewWillTransitionToSize:withTransitionCoordinator:

If the new rotation methods are not implemented, and a project is compiled with the iOS 8 SDK, the view controllers -will not receive calls- to the deprecated rotation methods.

My concern is this: What happens to an app already in the AppStore built with the iOS 7 SDK? Will the deprecated rotation methods still be called on an iOS 8 device or not?

EDIT:

The rotation methods are still called, but there exist some changes/issues/bugs in iOS 8.

Also UIScreen is now interface oriented

like image 836
fabb Avatar asked Aug 11 '14 08:08

fabb


1 Answers

I just had this issue and I wanted to use the same methods that I was using before (at least for now), so this is what I did.

- (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.     UIInterfaceOrientation toOrientation   = [[UIDevice currentDevice] orientation];     //fixes orientation mismatch (between UIDeviceOrientation and UIInterfaceOrientation)     if (toOrientation == UIInterfaceOrientationLandscapeRight) toOrientation = UIInterfaceOrientationLandscapeLeft;     else if (toOrientation == UIInterfaceOrientationLandscapeLeft) toOrientation = UIInterfaceOrientationLandscapeRight;      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];     }];  } 

I'm still not sure if I should use this outside of the animation block since I don't have the duration.

    [self willRotateToInterfaceOrientation:toOrientation duration:0.0]; 
like image 61
Camo Avatar answered Oct 05 '22 23:10

Camo