在iOS 8中不推荐使用InterfaceOrientation

Dee*_*rma 9 uikit uiinterfaceorientation autorotate auto-rotation ios8

我没有在我的项目中使用Size类,并继续使用旧方法进行视图控制器方向.我收到了弃用警告,例如当我使用下面的代码时:

    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
      ...
    }
Run Code Online (Sandbox Code Playgroud)

我搜索了很多但找不到合适的方法来修复它.有什么建议 ?

Tha*_*oth 9

应该改变

if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
  ...
}
Run Code Online (Sandbox Code Playgroud)

if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
  ...
}
Run Code Online (Sandbox Code Playgroud)


vme*_*yer 7

从iOS8开始,Apple建议使用TraitCollections(Size Classes)而不是interfaceOrientation.

此外,由于iOS 9和新iPad具有"多任务处理"功能,因此在某些情况下设备方向与窗口比例不符!(这会导致您的应用程序UI失效)

但是,有时TraitCollections不能满足您的所有设计需求.对于这些情况,Apple建议比较视图的界限:

if view.bounds.size.width > view.bounds.size.height {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

我很惊讶,但是你可以在2015年11月15日在iOS 9上的iPad上观看WWDC 2015视频多任务入门.


归档时间:

查看次数:

8043 次

最近记录:

7 年,7 月 前