iOS 8 Rotation Methods Deprecation - Backwards Compatibility

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


Solution 1:

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];

Solution 2:

The rotation methods are deprecated in the iOS 8 SDK. This will have no effect at all on apps built with the iOS 7 SDK, even running in iOS 8 and probably several future versions of iOS.

As an example, the font property of UIButton has been deprecated since iOS 3.0 and is still available in iOS 7.0.

Solution 3:

The deprecated rotation methods you've listed are still called when the app is run on iOS 8+ devices. If you are supporting iOS 7, you may continue to use them without issue. If you are only supporting iOS 8+, it would be wise to use the non-deprecated methods instead.

However, do note that if you implement the new rotation methods and the deprecated ones in the same view controller, when run on iOS 7 the deprecated methods will be called, and on iOS 8+ it will only call the new methods that have replaced those that are deprecated.

For example, if you only implement willRotateToInterfaceOrientation, this method will be called when run on iOS 7 and 8. If you then add viewWillTransitionToSize, iOS 7 will still call willRotateToInterfaceOrientation but iOS 8 will not, instead it will only call viewWillTransitionToSize.

Solution 4:

I would check that specific case to have 100% of confidence but I do not expect any troubles. I would also recommend you watching session 216 Building Adaptive Apps with UIKit from WWDC 2014 to get more informations. It looks like the depreciated methods are not called so the app should be updated to work properly with devices running iOS 8.

Solution 5:

For me, here we rotate "things manually" with some calculations and a plist file that track the size of headers and things like that (so if we want to change something buttons and so on, we only change this plist not all individual xibs). And all our rotation code is inside willLayoutSubviews so all things are correct even on new iOS8... except for I Also I did see that for new ios8 [[UIScreen mainScreen] bounds].size.width now return the width acording to device orientation not to device real size.

I will post this to other thread:

- (BOOL) isIOS8OrAbove{
    float version802 = 1140.109985;
    float version8= 1139.100000; // there is no def like NSFoundationVersionNumber_iOS_7_1 for ios 8 yet?
    NSLog(@"la version actual es [%f]", NSFoundationVersionNumber);
    if (NSFoundationVersionNumber >= version8){
        return true;
    }
    return false;
}