iOS 13 中 UISplitViewController 的详细信息窗格中出现了新的 UINavigationBar

New UINavigationBar appearance in detail pane of UISplitViewController in iOS 13

在 iOS 13 下,如果您在导航控制器中设置可滚动的根视图控制器(例如 UITableViewController),然后将该导航控制器放在 UISplitViewController 的详细信息窗格中,则导航栏的背景当可滚动内容位于顶部时不可见。

您可以通过基于 Master/Detail 模板创建一个新的 iOS 项目来看到这一点。然后修改情节提要以在详细信息窗格的导航控制器内使用 UITableViewController。将 device/simulator 置于 Light Appearance 模式(它比 Dark 模式更能显示问题)。 运行 应用程序,注意导航栏区域与 table 视图背景颜色相同。现在向上滚动 table 视图,导航栏颜色变为标准浅灰色。让 table 视图 return 到顶部,导航栏颜色再次消失。

我只在拆分视图控制器的详细信息窗格中看到过。

如何关闭此 "feature" 以便导航栏看起来正常,就像在除拆分视图控制器的详细信息窗格之外的其他任何地方使用的所有其他导航栏一样?

UISplitViewControllerUISplitViewControllerDelegate 没有相关的 API 更改。 UINavigationController里面也没有。

经过一番挖掘,我找到了一个解决方法,但我很想找到一种方法来避免必须这样做。

UINavigationBar class 现在有一些用于设置其外观的新属性。奇怪的是,UINavigationBar.

文档中的 "Customizing the Appearance of a Navigation Bar" 中提到了其中的 none

iOS13 中新增了三个属性:

三个都是UINavigationBarAppearance类型。

默认只设置第一个

即使 scrollEdgeAppearancenil,拆分控制器的详细信息窗格就像已将 backgroundColor 设置为 clear 颜色一样。

因此解决方法是将以下行添加到导航控制器的根视图控制器的 viewDidLoad 方法中:

navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance

为什么只有在这种情况下才需要这样做?除了添加这段代码,还有更正确的解决方案吗?

我注意到 none 的 Apple 应用程序(至少是邮件、便笺和文件)似乎使用此 "feature"。

您找到的解决方法是 'official' 禁用此行为的方法,正如 Apple iOS 系统体验团队的 David Duncan 在 thread on Twitter 中所解释的那样。

to control what happens when the UINavigationBar is completely unfurled, you want to set the scrollEdgeAppearance. By setting standardAppearance and scrollEdgeAppearance to the same values, you will get a bar that doesn't change.

不禁用此行为的 Apple 应用是“设置”应用。