ios – Reliably knowing when UISplitViewController shows the primary view


I have an app which supports both iPhone and iPad, and it uses an embedded UISplitViewController.

I’d like to manually control the sidebar visibility, so I have added a button to toggle it on/off. However, it turns out that iPhone and iPad treat the values differently.

On iPad, you can check the value of .displayMode to see if the split view is only presenting the secondary view:

if editorSplitView.displayMode == .secondaryOnly { // ...

But this does not work on iPhone, which always says the display mode is .oneBesideSecondary, no matter the setup. Even when the primary view is open, the value stays the same on iPhone. Checking splitView.isCollapsed doesn’t help either, as on a smaller screen either view is collapsed at all times anyway.

I know that implementing your own show/hide button is somewhat unorthodox but I have a justified use case. What’s the actual, preferred way to know the display mode on both devices?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img