简体   繁体   English

iOS 14 中的 UISplitViewController 在横向模式下按预期工作,但在纵向模式下不起作用

[英]UISplitViewController in iOS 14 works as intended in landscape mode, but not in portrait

I am trying to preserve the functionality of iOS 13 and UISplitViewController in my app for iOS 14. Everything works as intended (two side by side view controllers) in landscape mode, but if I launch the app (the split view controller is the initial view controller) in portrait, my conditional logic to show the primary view controller when a variable in the detail view controller is nil is not functioning properly AND the navigation bar (bar button items, large titles) for the primary and detail view controller is not visible.我试图在我的应用程序中为 iOS 13 和 UISplitViewController 保留 iOS 14 的功能。在横向模式下一切都按预期工作(两个并排视图控制器),但是如果我启动应用程序(拆分视图 controller 是初始视图控制器)在肖像中,当详细视图 controller 中的变量为 nil 时,我的条件逻辑显示主视图 controller 无法正常工作并且主视图和详细视图 controller 的导航栏(栏按钮项目,大标题)不可见.

func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool  {
        
        if (secondaryViewController is UINavigationController) && (((secondaryViewController as? UINavigationController)?.topViewController) is DetailViewController) && (((secondaryViewController as? UINavigationController)?.topViewController as? DetailViewController)?.dict == nil) {

            return true

        } else {

            return false

        }

    }

Strangely enough, if I launch the app in landscape and then move to portrait, the titles are there, the bars are there, and everything works as intended.奇怪的是,如果我以横向模式启动应用程序,然后切换到纵向模式,标题在那里,栏在那里,一切都按预期进行。 This seems to be an issue with first launch in portrait mode.这似乎是首次以纵向模式启动的问题。

The solution is to use the new delegate method topColumnForCollapsingToProposedTopColumn and return .primary or .secondary as needed.解决方案是使用新的委托方法topColumnForCollapsingToProposedTopColumn并根据需要返回.primary.secondary

I found another way to accomplish this:我找到了另一种方法来完成这个:

  1. Open your Main.storyboard打开你的Main.storyboard
  2. Right click your SplitViewController右键单击您的SplitViewController
  3. Click and drag a new relationship from " compact view " to your desired view controller.单击并将新关系从“ compact view ”拖动到您想要的视图 controller。

For me, this means I now have 2 relationships going from the SplitViewController to my Primary View Controller (2 relationship segues: "master view controller" and "compact view controller").对我来说,这意味着我现在有 2 个关系从SplitViewController到我的主视图 Controller(2 个关系 segues:“master view controller”和“compact view controller”)。 But, hey it works now.但是,嘿,现在可以了。 None of the delegate stuff was working for me no matter what I tried.无论我尝试什么,代表的东西都不适合我。

At the end of the day it seems like the Split View Controller has a property for which view controller is displayed in compact mode.在一天结束时,Split View Controller 似乎有一个属性,视图 controller 以紧凑模式显示。 You can set this in your storyboard, and that will determine which view is displayed in compact screens.您可以在您的 storyboard 中进行设置,这将决定在紧凑屏幕中显示哪个视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UISplitViewController在横向模式下显示为纵向 - UISplitViewController appears portrait in landscape mode iOS纵向和横向模式 - ios portrait and landscape mode UISplitViewController中的ActionSheet在纵向模式下的行为与横向模式不同 - ActionSheet within UISplitViewController acts different in Portrait Mode than Landscape Mode 当弹出窗口时,UISplitViewController在iOS 8中禁用横向旋转的肖像 - UISplitViewController portrait to landscape rotation disabled in iOS 8 when popover presented iOS 14 UISplitViewController 在 iPad 上移除横向的“隐藏/显示”按钮? - iOS 14 UISplitViewController remove "hide/show" button in landscape on iPad? IOS设备方向卡在纵向模式下,没有横向 - IOS Device Orientation Stuck at Portrait mode, no Landscape 在纵向模式下,尴尬的横向键盘,IOS 8 - Awkward Landscape keyboard in portrait mode, IOS 8 纵向模式下的动画UIView在ios的横向上不一致 - animated UIView in portrait mode is not consistent in landscape on ios 用于纵向和横向模式iOS的自定义界面 - Custom interfaces for Portrait & Landscape mode iOS iOS 8横向纵向模式下的自定义键盘 - Custom keyboard in iOS 8 landscape portrait mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM