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?
[splitViewCo
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.
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.
Have a look at APSplitViewController.
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!
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.
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.