iOS 8 Rotation Methods Deprecation - Backwards Compatibility
Asked Answered
Z

6

52

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

Zackaryzacks answered 11/8, 2014 at 8:15 Comment(1)
they are going to work well; they have been built with iOS7 SDK, when those methods were not deprecated yet. however, if you compile the project with iOS8 SDK (when it comes out), you will need to concern about that and update your project – but the old apps will be fine without further actions.Ur
R
19

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.

Rimose answered 11/8, 2014 at 8:37 Comment(7)
Have you got an Apple reference stating that?Zackaryzacks
@Zackaryzacks see here. "Deprecation does not mean the immediate deletion of an interface from a framework or library." and "deprecated APIs may be deleted from a future version of the OS". That is what deprecation means, that it may be removed from a future version of the OS.Rimose
i wonder who down-voted this without giving a reason. The answer is correct. We have tested it. One of our apps supports iOS 4.3 [an enterprise app] and it rotates perfectly on iOS8 beta5. Rotation call backs will only cause trouble if app is built with iOS 8 SDK.Retainer
I have an new issue related to orientation , this case happen when i rotate from landscape to portrait still the background image in UItableViewCell isn't changed , what is the best place to changed my background cell imageWillin
@tGilani: I have build an app in ios 5 & the rotation is working completely fine till ios 7 but in ios 8, if I rotate the screen from portrait to landscape left or landscape right the video in screen still runs in portrait mode in reference to that orientation.Eyeglasses
do not use xcode 6 to build your app or rotation will fail.Retainer
^ the above comment is the answer, it doesn't matter if you compile against 7.1 or lower using Xcode 6, you must use Xcode 5 too or change the deprecated methods.Lutenist
I
36

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];
Immaterialism answered 1/10, 2014 at 0:46 Comment(4)
One thing to note is that UIDeviceOrientation does not match UIInterfaceOrientation, specifically UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight and UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft so you can't mix and match them as you're doing in your viewWillTransitionToSize:withTransitionController: methodLoathly
Also, you need to call [super viewWillTransitionToSize:withTransitionController:] somewhere in it as wellLoathly
this is the enum for UIInterfaceOrientation typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft }; So you are right, I need to invert left and rightImmaterialism
Great answer. Hate viewWillTransitionToSize. But there is one problem: willAnimateRotationToInterfaceOrientation is called before animation (exactly like willRotateToInterfaceOrientation) - not during animation as before.Elocution
R
19

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.

Rimose answered 11/8, 2014 at 8:37 Comment(7)
Have you got an Apple reference stating that?Zackaryzacks
@Zackaryzacks see here. "Deprecation does not mean the immediate deletion of an interface from a framework or library." and "deprecated APIs may be deleted from a future version of the OS". That is what deprecation means, that it may be removed from a future version of the OS.Rimose
i wonder who down-voted this without giving a reason. The answer is correct. We have tested it. One of our apps supports iOS 4.3 [an enterprise app] and it rotates perfectly on iOS8 beta5. Rotation call backs will only cause trouble if app is built with iOS 8 SDK.Retainer
I have an new issue related to orientation , this case happen when i rotate from landscape to portrait still the background image in UItableViewCell isn't changed , what is the best place to changed my background cell imageWillin
@tGilani: I have build an app in ios 5 & the rotation is working completely fine till ios 7 but in ios 8, if I rotate the screen from portrait to landscape left or landscape right the video in screen still runs in portrait mode in reference to that orientation.Eyeglasses
do not use xcode 6 to build your app or rotation will fail.Retainer
^ the above comment is the answer, it doesn't matter if you compile against 7.1 or lower using Xcode 6, you must use Xcode 5 too or change the deprecated methods.Lutenist
G
6

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.

Gottfried answered 12/8, 2014 at 4:1 Comment(6)
didRotateFromInterfaceOrientation is not being called on an iOS 8 device despite having all the settings you mention above.Chaffer
@Chaffer didRotateFromInterfaceOrientation is called on iOS 8 12A365, I just tried it with a brand Swift new project. Very simple: new single view project, override didRotateFromInterfaceOrientation in ViewController and add NSLog("rotated"). It's logged after rotation completes on both iOS 7 and 8 for iPhone and iPad. In fact it's called even if you don't change the deployment target to iOS 7.Gottfried
There is obviously more to this then, my NSLog is not showing. Could it be because my didRotateFromInterfaceOrientation method is in a category and not a ViewController?Chaffer
@Chaffer Probably, I've never tried that. From the UIViewController Class Reference: "If a view controller is not visible when an orientation change occurs, then the rotation methods are never called."Gottfried
I'm not sure how that fits in. The method is definitely called on an iOS 7 device but not 8. There are other issues that I have with the category which only appear on 8 but no deprecation error appear or anything. Very strange and feels more like a bug than anything.Chaffer
I found that willRotate and didRotate are still called if I don't have the willTransition methods in the code. If I add willTransitionToTraitCollection and viewWillTransitionToSize then the willRotate and didRotate aren't called but if I remove the willTransition methods then the old ones are still called. This is with iOS 8.1 base SDK and a deployment target of 8.0.Downspout
P
2

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.

Polite answered 11/8, 2014 at 8:45 Comment(8)
Actually I tried running an app with the iOS 8 SDK. The deprecated methods are not called.Zackaryzacks
The mentioned rotation methods are called when the app is running on iOS 8 devices, at least if the deployment target is set properly.Gottfried
@Zackaryzacks they are called, probably you have set something improperlyPolite
Hm, then I must find out why some of my views do not resize when rotating when I compile with the iOS 8 SDK.Zackaryzacks
do you use autolayout?Polite
didRotateFromInterfaceOrientation is not being called for me either. Same code running in the simulator on a 7 device works fine but not 8.Chaffer
As there seems to be some confusion about whether the deprecaded methods are being called on iOS 8 or not: for me it turned out that they are called on the root view controller, but they are not called on child view controllers like they have been on iOS 7. HTH.Maternal
didRotateFromInterfaceOrientation will not be called if you have overriden viewWillTransitionToSizeFortepiano
Z
1

The rotation methods still work, BUT there exist other issues:

Zackaryzacks answered 29/9, 2014 at 7:12 Comment(0)
M
1

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;
}
Maclean answered 2/10, 2014 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.