相关疑难解决方法(0)

允许iPhone 6 Plus的横向,但不允许其他iPhone

在我的通用应用程序中,我当前supportedInterfaceOrientations在窗口的根视图控制器中覆盖以定义允许的方向.到目前为止,决定是基于设备的用户界面习语:

- (NSUInteger) supportedInterfaceOrientations
{
  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
  else
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

现在我想改变它,以便我也可以支持iPhone 6 Plus的风景,但不支持其他iPhone.我可以想象一两个解决方案,但这些都非常脆弱,并且可能会在Apple开始制造新设备时破坏.

在理想的世界中,我想将上述方法更改为以下代码段,其中决策基于设备的用户界面大小类而不是用户界面惯用语:

- (NSUInteger) supportedInterfaceOrientations
{
  // Note the hypothetical UIDevice method "landscapeSizeClass"
  if ([[UIDevice currentDevice] landscapeSizeClass] == UIUserInterfaceSizeClassCompact)
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
  else
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

landscapeSizeClass在UIKit的某个地方有类似神奇的方法吗?我在各种课程参考和指南中看了一下,但没有找到任何有用的东西.或者有人可以建议一个同样通用且面向未来的不同解决方案吗?

请注意,我的应用程序以编程方式创建其UI,因此纯粹基于故事板的解决方案已经完成.此外,我的应用程序仍然需要支持iOS 7,所以我不能只是改变一切使用大小类.但是,我可以做的是在使用简单的iOS 8 API之前进行运行时检查.

iphone objective-c ios iphone-6-plus

6
推荐指数
1
解决办法
789
查看次数

标签 统计

ios ×1

iphone ×1

iphone-6-plus ×1

objective-c ×1