Split view in portrait mode!

前端 未结 6 1542
梦毁少年i
梦毁少年i 2021-01-11 10:57

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         


        
相关标签:
6条回答
  • 2021-01-11 11:06

    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.

    0 讨论(0)
  • 2021-01-11 11:07

    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.

    0 讨论(0)
  • 2021-01-11 11:15

    Have a look at APSplitViewController.

    0 讨论(0)
  • 2021-01-11 11:20

    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!

    0 讨论(0)
  • 2021-01-11 11:21

    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.

    0 讨论(0)
  • 2021-01-11 11:33

    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.

    0 讨论(0)
提交回复
热议问题