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

Community
  • 1
  • 1
fabb
  • 11,660
  • 13
  • 67
  • 111
  • 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. – holex Aug 11 '14 at 08:37

6 Answers6

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];
Camo
  • 1,778
  • 14
  • 12
  • 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: method – iain Oct 03 '14 at 17:36
  • Also, you need to call [super viewWillTransitionToSize:withTransitionController:] somewhere in it as well – iain Oct 03 '14 at 17:40
  • 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 right – Camo Oct 03 '14 at 18:46
  • Great answer. Hate viewWillTransitionToSize. But there is one problem: willAnimateRotationToInterfaceOrientation is called before animation (exactly like willRotateToInterfaceOrientation) - not during animation as before. – Dmitry Mar 25 '15 at 19:20
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.

mluisbrown
  • 14,448
  • 7
  • 58
  • 86
  • Have you got an Apple reference stating that? – fabb Aug 14 '14 at 07:48
  • 3
    @fabb see [here](https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/cross_development/Using/using.html#//apple_ref/doc/uid/20002000-SW5). "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. – mluisbrown Aug 14 '14 at 10:18
  • 5
    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. – atastrophic Aug 27 '14 at 09:42
  • 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 image – wod Oct 19 '14 at 14:25
  • @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. – iYoung Oct 28 '14 at 06:20
  • 3
    do not use xcode 6 to build your app or rotation will fail. – atastrophic Oct 28 '14 at 13:10
  • 1
    ^ 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. – jigzat Nov 09 '14 at 00:29
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.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • 1
    didRotateFromInterfaceOrientation is not being called on an iOS 8 device despite having all the settings you mention above. – Leon Sep 23 '14 at 17:10
  • @Leon `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. – Jordan H Sep 23 '14 at 22:17
  • 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? – Leon Sep 24 '14 at 08:41
  • @Leon 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." – Jordan H Sep 24 '14 at 15:02
  • 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. – Leon Sep 24 '14 at 21:20
  • 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. – BountyBob Jan 28 '15 at 12:00
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.

Julian
  • 9,299
  • 5
  • 48
  • 65
  • 3
    Actually I tried running an app with the iOS 8 SDK. The deprecated methods are **not** called. – fabb Aug 11 '14 at 09:00
  • 1
    The mentioned rotation methods **are** called when the app is running on iOS 8 devices, at least if the deployment target is set properly. – Jordan H Aug 12 '14 at 04:03
  • @fabb they are called, probably you have set something improperly – Julian Aug 12 '14 at 14:09
  • Hm, then I must find out why some of my views do not resize when rotating when I compile with the iOS 8 SDK. – fabb Aug 14 '14 at 07:49
  • do you use autolayout? – Julian Aug 14 '14 at 07:49
  • didRotateFromInterfaceOrientation is not being called for me either. Same code running in the simulator on a 7 device works fine but not 8. – Leon Sep 23 '14 at 17:14
  • 2
    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. – chris Oct 28 '14 at 15:44
  • didRotateFromInterfaceOrientation will not be called if you have overriden viewWillTransitionToSize – JYC Jun 02 '15 at 03:55
1

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

Community
  • 1
  • 1
fabb
  • 11,660
  • 13
  • 67
  • 111
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;
}
tyoc213
  • 1,223
  • 18
  • 21