Configure the split-view controller to work in both iPhone and iPad
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
8d62cb3c1b
commit
78251e9a50
|
@ -20,4 +20,28 @@ class MainViewController: UISplitViewController {
|
||||||
|
|
||||||
super.loadView()
|
super.loadView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
self.delegate = self
|
||||||
|
|
||||||
|
// On iPad, always show both masterVC and detailVC, even in portrait mode, like the Settings app
|
||||||
|
self.preferredDisplayMode = .allVisible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension MainViewController: UISplitViewControllerDelegate {
|
||||||
|
func splitViewController(_ splitViewController: UISplitViewController,
|
||||||
|
collapseSecondary secondaryViewController: UIViewController,
|
||||||
|
onto primaryViewController: UIViewController) -> Bool {
|
||||||
|
// On iPhone, if the secondaryVC (detailVC) is just a UIViewController, it indicates that it's empty,
|
||||||
|
// so just show the primaryVC (masterVC).
|
||||||
|
let detailVC = (secondaryViewController as? UINavigationController)?.viewControllers.first
|
||||||
|
let isDetailVCEmpty: Bool
|
||||||
|
if let detailVC = detailVC {
|
||||||
|
isDetailVCEmpty = (type(of: detailVC) == UIViewController.self)
|
||||||
|
} else {
|
||||||
|
isDetailVCEmpty = true
|
||||||
|
}
|
||||||
|
return isDetailVCEmpty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue