diff options
author | Roopesh Chander <roop@roopc.net> | 2018-10-13 16:02:42 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-10-27 15:13:01 +0530 |
commit | 78251e9a50de98972d51e2b0c23ff72d3b1b4876 (patch) | |
tree | 5771857a91c7984028df3c2b66b57e5d23966e34 /WireGuard/WireGuard/UI/iOS/MainViewController.swift | |
parent | Change copyright to WireGuard LLC (diff) | |
download | wireguard-apple-78251e9a50de98972d51e2b0c23ff72d3b1b4876.tar.xz wireguard-apple-78251e9a50de98972d51e2b0c23ff72d3b1b4876.zip |
Configure the split-view controller to work in both iPhone and iPad
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/MainViewController.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/MainViewController.swift | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/MainViewController.swift index 25be277..e477f21 100644 --- a/WireGuard/WireGuard/UI/iOS/MainViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/MainViewController.swift @@ -20,4 +20,28 @@ class MainViewController: UISplitViewController { 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 + } } |