iosuisplitviewcontrollerios14

iOS 14 UISplitViewController remove "hide/show" button in landscape on iPad?


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)?


Solution

  • 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
    }