2016-02-29 66 views
2

在通用應用程序中,我無法找到始終顯示主控制器的方法(即使在iPhone 6 Plus中進行橫向旋轉) 。強制UISplitViewController始終僅在橫向上顯示主(僅在iPhone 6 Plus上)

我想達到什麼是看到UISplitViewController僅在iPad上,而不是iPhone的動作,不知道是否有可能

委託方法沒有幫助:

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 
    } 

回答

5

您需要重寫UISplitViewController的特徵集合以始終具有緊湊的大小類。要做到這一點,你需要插入容器視圖控制器爲您UISplitViewController的父:

  1. 嵌入您的UISplitViewController成ContainerViewController
  2. 添加以下代碼到你的容器視圖控制器子類覆蓋的特點集合你的孩子視圖控制器:

    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) 
        } 
    }} 
    

很好的解釋在Building Adaptive Apps with UIKit (WWDC 2014)

+0

大把戲!謝謝 – Enlil

相關問題