iPad SplitViewController with menu in portrait mode like settings app

拟墨画扇 提交于 2019-11-27 11:22:13

This is the magic you need:

This method is in UISplitViewControllerDelegate, available on iOS 5.0

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

You should definitely have a look at Matt Gemmell's MGSplitViewController.

MGSplitViewController is an open source replacement for UISplitViewController, with various useful enhancements.

Unfortunately, it's an undocumented method (i.e. private API).

[splitViewController setHidesMasterViewInPortrait:NO];

I think you need to create a custom view controller containing a table view (as the master controller) and another generic subview (as the detail controller) to simulate this.

The easiest way to get the effect you want may be to just not use a UISplitView. Instead, just create a normal view, put a table view on its left side, your detail view on the right side, and then set the autosizing stuff appropriately so that everything looks right in both portrait and landscape.

Since shouldHideViewController is deprecated in iOS8, you will need to use this instead (Swift):

splitViewController.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible

As ccwasden stated, shouldHideViewController is deprecated as of iOS8. In Objective-C, use...

splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;

some people asked me the same question on our blog and I found a solution for that. You will find it at the end of my blog post Your first split view controller | Seaside.

In general, all you have to do is to create a subclass of UISplitViewController and override the method willAnimateRotationToInterfaceOrientation: duration: and adjust your master and detail views when the interface orientation will change to portrait mode.

Cheers, Andreas

rjobidon

In Swift:

splitViewController.preferredDisplayMode = .allVisible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!