在通用应用程序中,即使在横向旋转的iPhone 6 Plus上,我也找不到始终显示(且仅)主控制器的方法。
我想要实现的是仅在iPad上而不是在iPhone上看到UISplitViewController起作用,不知道是否可能
委托方法无济于事:
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的trait集合,以始终具有紧凑的大小类。为此,您需要插入一个容器视图控制器作为UISplitViewController的父级:
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)