? ? UISplitViewController用于把屏幕分割為左右兩部分艘蹋,一般左邊顯示導(dǎo)航視圖婚瓜,在右邊顯示相應(yīng)的詳細(xì)信息稍途。從iOS8開始在iPhone上也可以使用了着逐。
? ? ? 一般UISplitViewController都被用在應(yīng)用的根視圖,我們?cè)?storyboard 上拖拽一個(gè)Split View Controller會(huì)是下圖這個(gè)樣子
我們這個(gè)基礎(chǔ)上再加上漆际,勾選 Is Initial Controller選項(xiàng)罩抗,還有給子視圖添加一個(gè)UINavigationController
最后我們只需要在AppDelegate 的
funcapplication(application:UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) ->Bool 方法
添加如下代碼
letsplitViewController =self.window!.rootViewControlleras!UISplitViewController
letnavigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1]as!UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem= splitViewController.displayModeButtonItem()
splitViewController.delegate=self
注意:相應(yīng)的代理方法還是要添加的 UISplitViewControllerDelegate
funcsplitViewController(splitViewController:UISplitViewController, collapseSecondaryViewController secondaryViewController:UIViewController, ontoPrimaryViewController primaryViewController:UIViewController) ->Bool{
guardletsecondaryAsNavController = secondaryViewControlleras?UINavigationControllerelse{returnfalse}
guardlettopAsDetailController = secondaryAsNavController.topViewControlleras?DetailViewControllerelse{returnfalse}
iftopAsDetailController.detailItem==nil{
// Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
returntrue
}
returnfalse
}