How to make split view work in portrait?

Declares

Well don’t I feel stupid. That’s what I get for reading Apple’s docs. :stuck_out_tongue:

You’ll need a declare and an enum, but this ONLY works on iPad and only on iOS 8 (it’ll crash the app on startup everywhere else):

In a module, define a global method:

[code]Sub DisplayMode(extends scr as iOSSplitView, assigns mode as ScreenDisplayMode)
declare sub setPreferredDisplayMode lib “UIKit” selector “setPreferredDisplayMode:” (obj as ptr, mode as integer)

dim intMode as integer = integer(mode)
setPreferredDisplayMode(scr.ViewControllerHandle, intMode)
End Sub[/code]

And an enum:

Public Enum ScreenDisplayMode Automatic = 0 PrimaryHidden AllVisible PrimaryOverlay

And then you can call it thusly:

self.ParentSplitView.DisplayMode = ScreenDisplayMode.AllVisible

From some experiments, the OS will still hide the lefthand view if the constraints on the right make it so there’s not enough space.

It’s also worth noting (in case you guys hadn’t figured it out) that the left-hand view in a split view is available on an iPad in portrait mode. Just swipe in from the left side of the screen and voila!

Thanks Greg! I’ll add this to my app and run some experiments.

Greg,

I thought I would try your suggestion but I’m not getting it right.

[quote]And then you can call it thusly:

self.ParentSplitView.DisplayMode = ScreenDisplayMode.AllVisible
[/quote]

Where do you put the above call? I’ve tried in the view open but always get a nil object exception.

Where should the enum go? Does it matter? I added it to the module where I added the global method.

Thanks

The enum goes in the module with the function and they both need to be global.

[quote=178070:@Peter Mitchell]And then you can call it thusly:
self.ParentSplitView.DisplayMode = ScreenDisplayMode.AllVisible[/quote]
This code can go anywhere. I was calling it from the open event of one of the views inside the split view.

That is what I did. Double checked and ran again. Still get a nil object exception. The ParentSplitView is nil when checked in the debugger.

Has anyone else tried this and got it to work? Can’t see what I might be doing wrong.

Note: I took the XojoNotes example app and modified it to try this. Added a module with the method and enum, both global, and then added the call in the Open event on one of the views.

perhaps this might help?
[Apple won’t allow cut/paste from their pages]
But basically it says that both views must support the desired orientation, even if one is not visible

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html

Just wanted to leave a note here incase anyone else runs into the issue I encountered with this. I was trying to use this code to force the splitview in portrait immediately upon app launch:

self.ParentSplitView.DisplayMode = ScreenDisplayMode.AllVisible

The problem is if you use that code before the Master view has been shown, there’s a very good chance the master view will be incorrectly displayed and very buggy (this could be related to the view having a visible title & an iOS table). I had a ton of problems with this and almost gave up on using a split view in portrait mode.

If you run into that issue, what you can do is:

  1. In your split view’s master view’s open event, create a timer that will trigger a method after a short delay (I used a period of 500).
  2. Have the triggered method call the code above to set the DisplayMode
  3. Next, also have that same method instantiate a new master view and assign it to the original master view’s parentSplitView.master property. This will basically fix all of the bugginess and display issues since it will now be loaded AFTER the DisplayMode has been changed.

Just FYI, if you don’t do this… The left-hand panel is still accessible. You can just swipe in from the left side of the device and it will appear. (iOS 8 & 9)

Right, thanks Greg. That just might be confusing or unapparent to the end user, so I posted that workaround for an always-on split view.

[quote=178798:@Dave S]perhaps this might help?
[Apple won’t allow cut/paste from their pages]
But basically it says that both views must support the desired orientation, even if one is not visible
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html[/quote]
That is the correct way to do it, thanks Dave. Here is the important part:

[code]// Objective C code:

  • (BOOL)splitViewController:(UISplitViewController *)svc
    shouldHideViewController:(UIViewController *)vc
    inOrientation:(UIInterfaceOrientation)orientation{
    return NO;
    }[/code]