I wish to change the frame of DetailViewController when splitViewController?.displayMode == .PrimaryOverlay, such that the DetailViewController view is never obscured by the MasterViewController. I have managed to get this working when navigating from splitViewController?.displayMode == .PrimaryHidden to splitViewController?.displayMode == .PrimaryOverlay in iPad portrait orientation, using a custom UISplitViewController with overriden viewDidLayoutSubviews method as described in jrc's answer here: Change the width of Master in UISplitViewController (see below). I have linked the UISplitViewController in storyboard to SplitViewController, and viewDidLayoutSubviews() is called on initial app load with iPad.
SplitViewController.swift
override func viewDidLayoutSubviews() {
var masterViewController = (self.viewControllers[0] as! UINavigationController).topViewController
var detailViewController = (self.viewControllers[1] as! UINavigationController).topViewController
// Adjust the width of the detail view
var detailViewFrame = detailViewController!.view.frame
detailViewFrame.origin.x += masterViewController!.view.frame.width
detailViewFrame.size.width -= masterViewController!.view.frame.width
detailViewController!.view.frame = detailViewFrame
detailViewController!.view.setNeedsLayout()
}
However, when I am in splitViewController?.displayMode == .PrimaryOverlay, and subsequently select a different item from MasterViewController, the DetailViewController frame reverts back to the default frame size and position. I have tried to fix this using the following (although calling viewDidLayoutSubviews() in this way is not recommended):
MasterViewController.swift
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
collapseDetailViewController = false
splitViewController?.viewDidLayoutSubviews()
}
Now when I select an item in MasterViewController.swift splitViewController?.viewDidLayoutSubviews() is being called, but I get strange readings when printing the DetailViewController's view.frame.origin.x and view.frame.width at the end of viewDidLayoutSubviews(). And even with these changes to the frame which seem to have been made, the DetailViewController view is still being obscured.
Would appreciate if some help on how to fix the DetailViewController frame so that it is never obscured even when selecting new items in a MasterViewController. I have not had luck implementing any UISplitViewController delegate methods for solving this, and I also tried reloading the SplitViewController with loadView at the end of didSelectRowAtIndexPath but this caused a freeze of the iPad screen.