iOS 13中UISplitViewController的详细信息窗格中的新UINavigationBar外观 [英] New UINavigationBar appearance in detail pane of UISplitViewController in iOS 13

查看:153
本文介绍了iOS 13中UISplitViewController的详细信息窗格中的新UINavigationBar外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Under iOS 13, if you setup a scrollable root view controller (such as a UITableViewController) in a navigation controller and then put that navigation controller in the detail pane of a UISplitViewController, then the nav bar's background isn't visible when the scrollable content is at the top.

您可以通过基于主/详细信息"模板创建一个新的iOS项目来看到此信息.然后修改情节提要以在详细信息窗格的导航控制器内使用UITableViewController.将设备/模拟器置于亮外观"模式(比暗"模式更好地显示了问题).运行该应用程序,并注意导航栏区域的颜色与表格视图背景的颜色相同.现在,向上滚动表格视图,导航栏的颜色将变为标准的浅灰色.让表格视图返回顶部,导航栏颜色再次消失.

You can see this by creating a new iOS project based on the Master/Detail template. Then modify the storyboard to use a UITableViewController inside the detail pane's nav controller. Put the device/simulator in Light Appearance mode (it shows the problem better than Dark mode). Run the app and notice the nav bar area is the same color as the table view background. Now scroll the table view up and the nav bar color changes to the standard light gray. Let the table view return to the top and the nav bar color disappears again.

我仅在拆分视图控制器的详细信息窗格中看到了这一点.

I've only seen this in the detail pane of a split view controller.

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

How do you turn off this "feature" so that the nav bar looks normal just like every other nav bar used anywhere else other than the detail pane of a split view controller?

UISplitViewControllerUISplitViewControllerDelegate没有相关的API更改. UINavigationController也没有任何内容.

There are no relevant API changes for UISplitViewController or UISplitViewControllerDelegate. There's nothing in UINavigationController either.

经过一番挖掘,我找到了一种解决方法,但我很想找到一种避免这样做的方法.

After some digging I found one workaround but I'd love to find a way to avoid having to do this.

UINavigationBar类现在具有一些用于设置其外观的新属性.奇怪的是,UINavigationBar文档中的自定义导航栏的外观"下都没有提到这些.

The UINavigationBar class now has some new properties for setting its appearance. Oddly, none of these are mentioned under the "Customizing the Appearance of a Navigation Bar" in the documentation for UINavigationBar.

iOS 13中有三个新属性:

There are three new properties in iOS 13:

  • standardAppearance
  • compactAppearance
  • scrollEdgeAppearance
  • standardAppearance
  • compactAppearance
  • scrollEdgeAppearance

所有三个类型均为UINavigationBarAppearance.

默认情况下仅设置第一个.

Only the first one is set by default.

即使scrollEdgeAppearancenil,拆分控制器的详细信息窗格的作用也好像是已将backgroundColor设置为clear颜色时设置的.

Even though scrollEdgeAppearance is nil, the detail pane of a split controller acts as if this has been set with the backgroundColor set to the clear color.

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

So the workaround is to add the following line to the viewDidLoad method of the navigation controller's root view controller:

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

为什么仅在这种情况下才需要?除了添加此代码,还有其他更正确的解决方案吗?

Why is this needed only in this one case? Is there a more correct solution other than adding this code?

我注意到,苹果的任何应用程序(至少包括邮件,便笺和文件)似乎都没有使用此功能".

I noticed that none of Apple's apps (Mail, Notes, and Files at least) seem to use this "feature".

推荐答案

您找到的解决方法是禁用此行为的官方"方法,如 Twitter上的线程,由Apple的iOS系统体验团队的大卫·邓肯(David Duncan)

The workaround you found is the 'official' way to disable this behavior, as explained in a thread on Twitter by David Duncan who is on the iOS System Experience team at Apple.

控制UINavigationBar完全放置时发生的情况 展开后,您要设置scrollEdgeAppearance.通过设置 将standardAppearance和scrollEdgeAppearance设置为相同的值 会得到一个不变的条形图.

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应用程序是设置"应用程序.

An Apple app that does not disable this behavior is the Settings app.

这篇关于iOS 13中UISplitViewController的详细信息窗格中的新UINavigationBar外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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