6

I have a UISplitViewController embedded in a UINavigationController with a UINavigationItem button to toggle the display of the master view in portrait orientation. I want to show the master view above the detail view when the view first loads in portrait orientation.

Any similar examples I have found show the master and detail views splitting the screen in portrait orientation, but I need the detail view to be full screen in portrait with the master view covering the detail view when the UISplitViewController first loads (as if the master view has been swiped out from the left). Does anyone know how to do that?

MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73

2 Answers2

10

Edit: It's not a duplicate. Answer discovered in the comments. The solution is to use preferredDisplayMode on UISplitViewController and setting it to UISplitViewControllerDisplayModePrimaryOverlay

Left the original answer for context to the comments and posterity.


Original Answer

This is a duplicate of this: UISplitViewController in portrait on iPhone shows detail VC instead of master

For reference, the solution in that case was to have the view controller that implements UISplitViewControllerDelegate use the following code:

- (BOOL)splitViewController:(UISplitViewController *)splitViewController
collapseSecondaryViewController:(UIViewController *)secondaryViewController
  ontoPrimaryViewController:(UIViewController *)primaryViewController {

    if ([secondaryViewController isKindOfClass:[UINavigationController class]]
        && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[DetailViewController class]]
        && ([(DetailViewController *)[(UINavigationController *)secondaryViewController topViewController] detailItem] == nil)) {

        // Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
        return YES;

    } else {

        return NO;

    }
}
Community
  • 1
  • 1
lewiguez
  • 3,813
  • 1
  • 25
  • 40
  • not a duplicate, that solution is for displaying either master or detail view. I am looking for an answer to display both master and detail at the same time, with the master view covering part of the detail view. Could you point me towards a different answer or post a new solution? – MSU_Bulldog Jan 08 '15 at 21:46
  • Ah. I misread. There is a `preferredDisplayMode` property on UISplitViewController. Does that work? Not sure what the property is off the top of my head. – lewiguez Jan 08 '15 at 21:55
  • 1
    it does actually work, you just set it equal to UISplitViewControllerDisplayModePrimaryOverlay.. Thanks! – MSU_Bulldog Jan 08 '15 at 22:00
2

Alternatively you can use:

    - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController: (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {

    //  Force master view to show in portrait and landscape

    return NO;
}
bhavesh
  • 109
  • 14
Reefwing
  • 2,242
  • 1
  • 22
  • 23
  • 1
    This fixed my issue. I've found that the default behaviour is different between the newer buttonless iOS devices with FaceID to the traditional buttoned ones with TouchID. I'd designed the app to work with split views side by side, not with the master overlapping and popping in and out. This bit of code you've provided fixes it to the older (& better IMHO) side by side style. – Seoras Aug 15 '19 at 23:29