13

Apple provide the split view only for landscape but not for the portrait mode. Is there any way to achieve the splitview in portrait mode also?

[splitViewController setHidesMasterViewInPortrait:NO];

This will work. But this API is not documented(private).

Thanks,
Manjunath

Manjunath
  • 4,545
  • 2
  • 26
  • 31

6 Answers6

23

For iOS5+,

Go to your detailViewController. Your detailViewController should have UISplitViewControllerDelegate. And simply just drop this code in:

- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation{
    return NO;
}

This will do the trick. And it is public API.

Byte
  • 2,920
  • 3
  • 33
  • 55
17

My little contribution here.

Byte's answer is correct up until iOS 7. Starting in iOS 8 you should use preferredDisplayMode

For example, to show both view controllers in portrait mode do the following:

self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;

Hope this helps!

LuisCien
  • 6,362
  • 4
  • 34
  • 42
  • 1
    I subclassed the UISplitViewController and attached it to the splitview in the storyboard and in the viewdidload put self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible; – fellowworldcitizen Nov 17 '14 at 11:12
3

update in iOS 8 xcode 6+

if let splitVCExists = self.splitViewController{
        splitVCExists.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
    }    

doc: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISplitViewController_class/index.html#//apple_ref/occ/instp/UISplitViewController/preferredDisplayMode

One thing I did notice is that it will try to layout the splitviewcontroller based on the preferredDisplayMode as long as there is enough space. otherwise it will choose the display mode to fit the content right. I have used it and it lays the VCs out how I want in both portrait and landscape.

ImpactZero
  • 547
  • 4
  • 8
2

Take a look at this MGSplitViewController.

It is a customized split view controller with various useful enhancements. Certainly that you can show master view in portrait.

Son Nguyen
  • 3,481
  • 4
  • 33
  • 47
2

Have a look at APSplitViewController.

Darryl E. Clarke
  • 7,537
  • 3
  • 26
  • 34
Mustafa
  • 20,504
  • 42
  • 146
  • 209
0

Sometime back I tried to achieve a similar thing. After trying Matt's code, and unsucessfully trying to create a category I realized that the only way to do this(in a way that Apple doesn't reject your app) is to use two custom views. Refer this question.

Community
  • 1
  • 1
Vin
  • 10,517
  • 10
  • 58
  • 71