5

我正在为 iOS 13 准备应用程序,并在导航栏中使用搜索控制器出现错误。如何解决导航栏故障?

let search = UISearchController(searchResultsController: nil)

search.dimsBackgroundDuringPresentation = false
search.searchResultsUpdater = self
search.hidesNavigationBarDuringPresentation = false
self.definesPresentationContext = true
search.searchBar.isTranslucent = false

self.navigationItem.searchController = search

self.navigationItem.hidesSearchBarWhenScrolling = true

在此处输入图像描述

按取消,导航栏项目变得不可触摸。推送视图控制器会导致导航栏项目重叠。

在此处输入图像描述

我在 git https://github.com/eKroman/TESTsearchBar上创建了测试项目

从 Xcode 11 从 beta 7(可能是较旧的 beta)到 Xcode 11 GM 种子 2,在 iOS 13 beta(在 iPad 上测试)上出现错误。不会出现在模拟器上。

4

3 回答 3

10

我遇到了同样的问题,如果我取消 searchBar 并更改 navigationItem.title 那么我有一个 double title 。这就像导航栏的幽灵层停留在导航控制器中。

这就是我修复它的方法:

searchController.hidesNavigationBarDuringPresentation = true

可能最好在 Apple 解决此问题之前使用它。

我还注意到后退按钮切换到默认颜色(蓝色),好像导航栏 TintColor 已重置。

配置: - Xcode 11.0 (11A420a) - iOS 13.1 (17A5844a)

于 2019-09-19T12:16:34.690 回答
0

对于@CoachThys 的答案中的后退按钮重置为默认颜色(蓝色),我设法通过下面的代码解决它。

if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    /* .. set other things on appearances */
    appearance.buttonAppearance.normal.titleTextAttributes = [.foregroundColor: color]

    standardAppearance = appearance
    compactAppearance = appearance
    scrollEdgeAppearance = appearance
}

但是,我找不到解决仍然短暂重置为蓝色的背面指示器图像的方法。

于 2019-09-23T10:45:18.497 回答
0

添加带有图像的自定义后退按钮将修复新错误。这对我来说很有用。

        let negativeSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        negativeSpacer.width = -8
        self.navigationItem.leftBarButtonItems = [negativeSpacer, leftBarButtonItem]
于 2019-09-26T03:12:11.200 回答