Reputation: 535850
In iOS 14, the new split view controller handles the bar button items for you. That's cool! So in portrait we see this:
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:
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)?
Upvotes: 9
Views: 3894
Reputation: 700
In SwiftUI, this solution works – tested on iOS 16!
extension UISplitViewController {
open override func viewDidLoad() {
preferredDisplayMode = UISplitViewController.DisplayMode.oneBesideSecondary
// remove sidebar button, make sidebar always appear !
presentsWithGesture = displayMode != .oneBesideSecondary
}
}
Upvotes: 8
Reputation: 535850
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
}
Upvotes: 10