Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 396
Deepak Sharma Avatar asked Apr 18 '15 13:04

Deepak Sharma


2 Answers

Should change

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

to

if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
  ...
}
like image 112
Tharoth Avatar answered Oct 23 '22 05:10

Tharoth


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.

like image 27
vmeyer Avatar answered Oct 23 '22 05:10

vmeyer