问题描述
在通用应用程序中,我无法找到始终显示(且仅限)主控制器的方法,即使在横向旋转的iPhone 6 Plus上也是如此。
In a Universal App I can't find a way to always show (and only) the master controller, even on iPhone 6 Plus in landscape rotation.
我想实现的是看到UISplitViewController仅在iPad上运行而不在iPhone上运行,不知道是否可能
What I want to achieve is to see UISplitViewController in action only on the iPad and NOT on the iPhone, don't know if it's possible
委托方法无效:
func splitViewController(svc: UISplitViewController, shouldHideViewController vc: UIViewController, inOrientation orientation: UIInterfaceOrientation) -> Bool {
return false
}
func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
return true
}
推荐答案
您需要覆盖UISplitViewController的特征集合,以便始终拥有紧凑的大小类。为此,您需要插入容器视图控制器作为UISplitViewController的父级:
You need to override the trait collection of your UISplitViewController to always have a compact size class. To do so you need to insert a container view controller as the parent of your UISplitViewController:
- 将UISplitViewController嵌入到ContainerViewController中
-
将以下代码添加到容器视图控制器子类中以覆盖子视图控制器的特征集合:
- Embed your UISplitViewController into a ContainerViewController
Add the following code into your container view controller subclass to override the trait collection of your child view controller:
class ContainerVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
performOverrideTraitCollection()
}
private func performOverrideTraitCollection() {
for childVC in self.childViewControllers {
setOverrideTraitCollection(UITraitCollection(horizontalSizeClass: .Compact), forChildViewController: childVC)
}
}}
很好的解释使用UIKit构建自适应应用程序(WWDC 2014)
这篇关于强制UISplitViewController始终以横向显示主(仅限)(在iPhone 6 Plus上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!