Search code examples
ios8uikituiinterfaceorientationautorotate

InterfaceOrientation deprecated in iOS 8


I am not using Size classes in my project and continue to use old methods for view controller orientation. I am getting deprecation warnings, such as when I use code below :

    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
      ...
    }

I have searched a lot but could not find the right way to fix it. Any suggestions ?


Solution

  • Since iOS8, Apple recommends to use TraitCollections (Size Classes) instead of interfaceOrientation.

    Moreover, since iOS 9 and the new iPad feature "Multitasking", there are some cases where the device orientation doesn't fit with the window proportions ! (This leads to brake your application UI)

    However, sometimes TraitCollections doesn't fill all your design needs. For those cases, Apple recommends to compare view's bounds :

    if view.bounds.size.width > view.bounds.size.height {
        // ...
    }
    

    I was quite surprised, but you can check on the WWDC 2015 video Getting Started with Multitasking on iPad in iOS 9 at 21'15.