Forcing an iPad app to show splitView even in Portrait orientation(Like the Settings iPad app)
Asked Answered
D

9

4

I am trying to develop a splitView based iPad app, that displays the split interface in every orientation. I have tried subclassing the UISplitViewController class as given in this tutorial, but it doesn't work. I tried creating a category to set _hidesMasterViewInPortrait = (hidden) ? 0 : 1;, as suggested in one of the comments in the above blog, but nothing worked.

Can anyone help me to find a way out of this, without using any third party frameworks or classes?

Discomfort answered 7/1, 2011 at 9:45 Comment(1)
Hi, there is a very simple and effective way that: [splitViewController setHidesMasterViewInPortrait:NO]; But it is a undocumented API, that's mean Apple does not allow us to use it. Cannot believe!Koenig
R
1

I never achieved to force the SPlitViewController to do that but since you need to create controllers for both parts, you can just reuse those controllers to display the content the way you want it.

Recha answered 7/1, 2011 at 10:13 Comment(1)
I think this would be the most viable option in light of Jilouc's commentDiscomfort
G
14

In iOS8 (Swift), use this:

splitViewController.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
Grim answered 14/9, 2014 at 23:13 Comment(2)
renamed to UISplitViewControllerDisplayMode.allVisible in swift 4.0Exotoxin
UISplitViewControllerDisplayMode.allVisible is deprecated in ios 14, use UISplitViewController.DisplayMode.oneBesideSecondaryBerkow
C
13

In the viewController class that implements the UISplitViewControllerDelegate Protocol (usually the DetailViewController), add the following code.

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

According to the Docs, this has been available since iOS 5.

To see it in action:
-open Xcode.
-Create a new Master/Detail app.
-Add the above code to the DetailViewController
-Run in the iPad simulator.

In your own project you'll want to add the following line to the viewDidLoad method of the detailViewController.

self.splitViewController.delegate = self;
Clothilde answered 20/11, 2012 at 12:10 Comment(2)
Note that this is deprecated in iOS 8.Lenzi
For iOS 8, set the SplitViewController's preferredDisplayMode to AllVisibleClothilde
W
3

What you are describing sounds like Apple's Settings app (on iPad). My intuition would be that this is not a UISplitView. It's just a view containing two table views. Fix the layout manually when the device rotates. In other words, if you don't want what a UISplitView does, then you don't a UISplitView at all.

EDIT 12/19/2011: In iOS 5 the problem is basically solved, since you can now define your own container view controller, plus you can prevent the dismissal of the left view in a split view.

Whorled answered 10/1, 2011 at 0:56 Comment(0)
D
2

I'm not sure that it is possible with standard SplitViewController, but you can use custom one from

https://github.com/mattgemmell/MGSplitViewController

Desmonddesmoulins answered 7/1, 2011 at 10:28 Comment(3)
Thanks for your response, but as I said in my post I am trying to find a solution without using any third party classes. Maybe if you have gone throw the project in the given link , you could help me out on how do they do it!Discomfort
There is no official way to do this and setting _hidesMasterViewInPortrait is leading to app rejection IMHO (as it's clearly private stuff).Weitzel
+1 for that information. I think I would try to implement VdesmedT's answerDiscomfort
R
1

I never achieved to force the SPlitViewController to do that but since you need to create controllers for both parts, you can just reuse those controllers to display the content the way you want it.

Recha answered 7/1, 2011 at 10:13 Comment(1)
I think this would be the most viable option in light of Jilouc's commentDiscomfort
K
1

you can subclass UISplitViewController, then overwrite following method:

 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval) duration
Koenig answered 21/3, 2011 at 2:39 Comment(0)
C
0

hello my first post and i hope to help:

here is the way it works

[splitViewController setHidesMasterViewInPortrait:NO];
Cherri answered 3/4, 2011 at 10:18 Comment(0)
B
0

You cannot have Apple' splitViewController behave like that (and get in the app store). You would need to write your own container view controller. See Apple' docs

Burgenland answered 3/1, 2012 at 16:35 Comment(0)
T
0
you just need to add this delegate method to your detail view manager

    - (BOOL)splitViewController:(UISplitViewController *)svc 
       shouldHideViewController:(UIViewController *)vc 
                  inOrientation:(UIInterfaceOrientation)orientation
    {
        // Hide split view in portrait mode
        //return UIInterfaceOrientationIsPortrait(orientation);

        // Show Split view in portrait mode
        return NO;
    }

//vKj
Thorncombe answered 21/11, 2013 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.