在我的通用应用中,我目前在窗口的根视图控制器中覆盖了supportedInterfaceOrientations
来定义允许的方向。直到现在,决策都是基于设备的用户界面风格:
- (NSUInteger) supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
else
return UIInterfaceOrientationMaskAll;
}
现在我想修改这个问题,以便我还可以支持iPhone 6 Plus的横屏显示,但不支持其他iPhone设备。我可以想象出一两个解决方案,但这些解决方案都比较脆弱,并且可能会在苹果推出新设备时失效。
在理想情况下,我希望将上述方法更改为以下片段,其中决策基于设备的用户界面大小类而不是用户界面风格:
- (NSUInteger) supportedInterfaceOrientations
{
// Note the hypothetical UIDevice method "landscapeSizeClass"
if ([[UIDevice currentDevice] landscapeSizeClass] == UIUserInterfaceSizeClassCompact)
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
else
return UIInterfaceOrientationMaskAll;
}
有没有类似于UIKit中神奇的“landscapeSizeClass”方法?我在各种类引用和指南中都找了一些,但是没有找到有用的东西。或者有人可以建议一个不同的解决方案,它同样具有通用性和未来性吗?
请注意,我的应用程序是通过编程方式创建其UI的,因此纯粹基于故事板的解决方案是行不通的。此外,我的应用程序仍然需要支持iOS 7,因此我不能只是改变所有内容以使用大小类。但是,我可以在使用简单的iOS 8 API之前进行运行时检查。