[英]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:我找到了另一种方法来完成这个:
Main.storyboard
Main.storyboard
SplitViewController
SplitViewController
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.