UISplitViewController在iPhone(5或6)上不起作用 [英] UISplitViewController doesn't work on iPhone(5 nor 6)

查看:114
本文介绍了UISplitViewController在iPhone(5或6)上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPad上,我的UISplitViewController运行良好.我可以隐藏并显示其primaryViewController,并以适当的方式调用 splitViewController:willChangeToDisplayMode:.

On iPad, I have perfectly working UISplitViewController. I can hide and show its primaryViewController, and splitViewController:willChangeToDisplayMode: is called in appropriate way.

但是在iPhone上,出了点问题.
我可以显示primaryViewController,但不能将其隐藏,因为primaryViewController以全屏尺寸显示.它太满了,我无法触摸辅助视图,这样就可以在iPad上隐藏primaryViewController.
splitViewController:willChangeToDisplayMode:也不被调用.

But on iPhone, something is wrong.
I can show primaryViewController, but cannot hide it, because the primaryViewController appears in full screen size. It's so full that I can't touch the secondary view, in that way I can hide the primaryViewController on iPad.
splitViewController:willChangeToDisplayMode: is not called either.

在我的自定义UISplitViewController类中,下面有一个viewDidLoad.

I have a viewDidLoad below, in my custom UISplitViewController class.

// UISplitViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    self.preferredPrimaryColumnWidthFraction = .1;
    CGRect mainScreen = [[UIScreen mainScreen] bounds];
    self.minimumPrimaryColumnWidth = 270;
    self.maximumPrimaryColumnWidth = mainScreen.size.width - 5;
}

在iPhone上,以下任何属性似乎都不起作用: preferredPrimaryColumnWidthFraction或minimum/maximumPrimaryColumnWidth

On iPhone, any of these property seems not to be working: preferredPrimaryColumnWidthFraction or minimum/maximumPrimaryColumnWidth

我通过以下代码在AppDelegate.m中将此splitViewController添加为rootViewController.

I am adding this splitViewController as rootViewController in AppDelegate.m by the code below.

// AppDelegate.m
[_splitViewCon addChildViewController: tagNaviCon];
[_splitViewCon addChildViewController: mainNaviCon];
self.window.rootViewController = _splitViewCon;

我在网上搜索了一些关键词,例如容器视图".
当我想在iPhone上使用UISplitViewController时,这与我有关系吗?
我也看过WWDC视频,但是我不理解如何精确编码" .

I searched web and found some keywords like "container view".
Is this something I have to do with, when I want to use a UISplitViewController on iPhone ?
I also watched WWDC Video, but I didn't understand "how to code it exactly".

当前,我不使用任何Interface Builder.因此,如果有人提供编程方式进行编码,我会感到非常高兴.

Currently, I do not use any Interface Builder. So I'd be rather glad if someone gives programmaticaly way to code it.

谢谢!

推荐答案

您还可以在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

这篇关于UISplitViewController在iPhone(5或6)上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆