3
votes

In iOS 14, the new split view controller handles the bar button items for you. That's cool! So in portrait we see this:

enter image description here

We're in portrait, so that button at the top left summons the "overlay" version of the Primary column.

And in landscape we see this:

enter image description here

We're in landscape, so that button at the top left hides or shows the "side by side" version of the Primary column.

Now I want to know how to control the presence of these buttons individually. I see that I can set presentsWithGesture to false to hide both buttons, but that's not what I want. My question is: how can I hide the second button (landscape) but not the first button (portrait)?

1
@dfd I can't work out what you're hinting at, sorry. - matt
@dfd I'm afraid I don't know what a "navigation bar override" is. - matt
@dfd I wasn't able to find a way to do that. My attempts to say things to self.navigationItem failed to suppress the button. - matt
Deleted our conversation, as it really didn't help and was noise. Apple decided that the default behavior for a UISplitViewController "is what it is" - and the lack of other comments/answers implies that. A few years ago I was faced with an issue where portrait/landscape orientation meant more than Apple defaults - first in IB (Xcode 8?), then with size classes (at the time iPads were always regular). I now see that split screen changes that for iPads. Maybe in a year or two this default behavior will make it more apparent. - dfd
@dfd thanks, it's okay, I figured it out - matt

1 Answers

4
votes

Set a delegate on the split view controller and implement this delegate method:

func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) {
    svc.presentsWithGesture = displayMode != .oneBesideSecondary
}