且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UISplitViewController在iPhone(5或6)上不起作用

更新时间:2023-02-06 12:06:10

您还可以在iPhone 4S,5、5S和6上同时使用UISplitViewController.为此,您必须将其视图嵌入另一个视图控制器( addChildViewController: ... didMoveToParentViewController:)

You can have side-by-side UISplitViewController on iPhones 4S, 5, 5S and 6 as well. To do it you have to embed its view in another view controller (addChildViewController:...didMoveToParentViewController:)

此后,您将能够通过覆盖其特征集合( setOverrideTraitCollection:forChildViewController:)来控制split的行为.基本上,这里您必须检查当前的特征集,并将水平尺寸类别更改为常规.这样,通过设置split的 preferredDisplayMode

After that you'll be able to control split's behaviour by overriding its trait collection (setOverrideTraitCollection:forChildViewController:). Basically here you have to inspect your current trait collection and change the horizontal size class to regular. This way the UISplitController will be able to show both master and detail views (primary and secondary now called) by setting split's preferredDisplayMode

然后,在旋转时,您可以对特征集进行相同的观察,并更改preferredDisplayMode,并在必要时再次覆盖拆分的特征集.可以在 viewWillTransitionToSize:withTransitionCoordinator: willTransitionToTraitCollection:withTransitionCoordinator:中完成.由于iPad的尺寸级别在两个方向上都是常规的,因此不会在iPad上调用第二个.

Then on rotation you can make the same observations about your trait collection and change the preferredDisplayMode and override again if necessary the split's trait collection. This can be done in viewWillTransitionToSize:withTransitionCoordinator: or willTransitionToTraitCollection:withTransitionCoordinator:. The second one won't be called on an iPad as its size classes are alway regular on both orientations.

关于我仍然无法解决的问题的注释.例如,在iPhone 5S上以纵向旋转时,我将隐藏主控制器,以便在屏幕上仅显示一个视图,并且UISplitViewController应该使自己适应UINavigationController.效果很好,但是在旋转动画期间,主视图消失了,您可以看到一个空白的丑陋空间.

One note about a problem I'm still not able to resolve. On iPhone 5S for example when rotating in portrait I'm hiding the master controller so to have only one view on the screen and the UISplitViewController should adapt itself to a UINavigationController. That works fine however during the rotation animation the master view is disappearing and you can see a blank ugly space.

还有一个便条.
您必须实现UISplitViewControllerDelegate并使用方法,以便设置在应用启动时以及将拆分用作导航时应显示哪个视图控制器.
此处是关于此的主题

One other note as well.
You have to implement UISplitViewControllerDelegate and use methods in order to set which view controller should be visible on app launch and when split is used as a navigation.
Here is a thread about this.

希望这会有所帮助,如果我找到解决问题的方法,我将更新我的答案

Hope it helps and if I find solution about the problem I have I'll update my answer