打开UISplitViewController到主视图而不是详细信息 [英] Open UISplitViewController to Master View rather than Detail

查看:141
本文介绍了打开UISplitViewController到主视图而不是详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有目标iPhone 6应用程序的拆分视图界面。在第一次启动应用程序时,它将打开详细信息视图;我希望它能打开主视图。我试过了:

I have a split-view interface with a target iPhone 6 application. On the first launch of the application, it opens to the Detail View; I would like it to open to the Master View. I have tried:

self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryOverlay

其他地方建议(之前的StackOverFlow问题)但它似乎没有做任何事情,并且在启动时不会打开主视图。我还尝试将以下行添加到我的AppDelegate:

Which was suggested elsewhere (Prior StackOverFlow Question) but it doesn't seem to do anything, and does not open the Master view on launch. I also tried to add the following line to my AppDelegate:

splitViewController:collapseSecondaryViewController:ontoPrimaryViewController:

但是尽管返回true或false(另一个先前的堆栈溢出问题)我没有成功。

But despite returning true or false (Another Prior Stack Overflow Question) I had no success.

我做了在Xcode中启动示例Master-Detail应用程序,并根据splitViewController加载到Master视图:call returns false;但是,我不确定如何在更复杂的布局中完成这项工作。

I did launch up the example Master-Detail application in Xcode, and it loads to the Master view based on the splitViewController: call returning false; however, I'm not sure how to make this work in a more complicated layout.

推荐答案

Swift



UISplitViewController在纵向上显示主视图上方的详细信息不是关于显示主视图,它是关于在主视图下方以全宽显示详细信息视图。

Swift

UISplitViewController display master view above detail in portrait orientation is not about showing the Master view, it is about presenting the Detail view in full width, underneath the Master view.

UISplitViewController在iPhone上的肖像显示详细信息VC而不是主屏幕是关于崩溃机制的原理。

UISplitViewController in portrait on iPhone shows detail VC instead of master is about the principle of the collapse mechanism.

本答案地址:


  • Master→Detail (Compact)宽度)


    • iPhone 4s,5,5s,SE,6,6s,7(任意方向)

    • iPod Touch

    • 任何iPhone Plus(人像)

    • Master → Detail (Compact width)
      • iPhone 4s, 5, 5s, SE, 6, 6s, 7 (any orientation)
      • iPod Touch
      • any iPhone Plus (portrait)

      • iPad

      • 任何iPhone Plus(风景)

      您必须设置 preferredDisplayMode 。你想要的是 .primaryVisible 如果它存在的话!使用 .allVisible ,iOS选择详细信息如果只有1个视图适合(紧凑宽度);在这个大小,下面的代码将选择

      You must set preferredDisplayMode. You would want is .primaryVisible if it existed! Using .allVisible, iOS picks Detail if only 1 view fits (Compact width); in that size, the code below will pick Master.

      诀窍是改变两者 preferredDisplayMode .allVisible 返回 true in collapseSecondary:into

      The trick is to change both the preferredDisplayMode to .allVisible and to return true in collapseSecondary:onto.

      class PrimarySplitViewController: UISplitViewController,
                                        UISplitViewControllerDelegate {
      
          override func viewDidLoad() {
              self.delegate = self
              self.preferredDisplayMode = .allVisible
          }
      
          func splitViewController(
                   _ splitViewController: UISplitViewController,
                   collapseSecondary secondaryViewController: UIViewController,
                   onto primaryViewController: UIViewController) -> Bool {
              // Return true to prevent UIKit from applying its default behavior
              return true 
          }
      }
      

      这篇关于打开UISplitViewController到主视图而不是详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆