UISplitViewController-防止在iPhone 6 plus上横向拆分 [英] UISplitViewController - prevent splitting in landscape on iPhone 6 plus
问题描述
我在我的应用程序中使用UISplitViewController.在始终可以看到主要和次要对象的iPad上,它可以很好地工作;在像UINavigationController一样工作的大多数iPhone上,也可以很好地工作.
I am using a UISplitViewController in my app. This works just fine on iPad where primary and secondary are always visible, and it works just fine on most iPhones where it acts like a UINavigationController.
在iPhone 6+和6S +上,分割视图的作用类似于竖屏的iPhone和横屏的iPad.这种景观分裂给我带来了问题,我想避免这种情况.
On iPhone 6+ and 6S+ the split view acts like an iPhone in portrait and like an iPad in landscape. This splitting in landscape is causing me problems and I'd like to avoid it.
有什么方法可以防止UISplitViewController在iPhone 6+环境中显示主要和辅助控制器吗?我只希望它显示辅助控制器,就像其他iPhone一样.
Is there any way to prevent the UISplitViewController from showing primary and secondary controllers in iPhone 6+ landscape? I just want it to show the secondary controller, the same as it would do for other iPhones.
谢谢.
推荐答案
我能够通过将UISplitViewController子类化,然后重写特质集合以在设备不是iPad时返回紧凑的水平尺寸类来做到这一点.我知道现在检查接口习惯用法是虚假的,但是我不确定该怎么做.
I was able to do this by subclassing the UISplitViewController and then overriding the trait collection to return a compact horizontal size class when the device is not an iPad. I know checking the interface idiom is a faux-pas these days, but I wasn't sure how else to do it.
我只是将此方法添加到我的UISplitViewController子类中:
I simply added this method to my UISplitViewController subclass:
-(UITraitCollection *)traitCollection {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return [super traitCollection];
} else {
return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
}
}
当然欢迎任何提出更好方法的建议.
Any suggestions for a better way to do this are certainly welcome.
这篇关于UISplitViewController-防止在iPhone 6 plus上横向拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!