使用UISearchController时,iOS 13 UIBarButtonItem不可单击且UINavigationBars重叠

fl0*_*034 36 uinavigationcontroller ios uisearchcontroller ios13

我有一个导航栏,其中包含一些UIBarButtonItem按钮和类似的UISearchBar挂钩

var searchController: UISearchController!

override func viewDidLoad() {
    super.viewDidLoad()

    title = "Test"

    tableView.delegate = self
    tableView.dataSource = self

    searchController = UISearchController(searchResultsController: nil)
    navigationItem.searchController = searchController

    // This leads to the bug
    searchController.hidesNavigationBarDuringPresentation = false

    navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(leftTapped))
    navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(rightTapped))
}
Run Code Online (Sandbox Code Playgroud)

场景:我点击搜索栏,然后点击取消。

  • 问题1:除非我触摸屏幕的最外面的像素,否则条形按钮对触摸没有反应(仅在模拟器和鼠标单击时才可能)。

  • 问题2:当我按下另一个视图控制器时,导航项重叠

在此处输入图片说明

当我使用hidesNavigationBarDuringPresentation = true它时,它的工作就像预期的那样。


该问题出现在使用Xcode 11.0和11.1的带槽口和非带槽口的iPhone iOS 13.0和13.1上。

这是整个测试项目:https : //github.com/fl034/HidesNavigationBarDuringPresentationTest


我已经提起雷达(您也应该提起诉讼),但是也许你们中的有些人已经找到了解决方法?


更新1:iOS 13.1.1中仍然存在错误


更新2:错误已在iOS 13.2 Beta中修复(感谢@Ben Gomm)

mat*_*att 8

视图调试器揭示了此错误的原因。导航栏的内容正在复制。在显示搜索之前,导航栏如下所示:

在此处输入图片说明

然后是下面的样子:

在此处输入图片说明

问题是两个副本视图和额外的UILabel。我不知道他们在做什么,也找不到删除他们的方法。

编辑顺便说一句,我认为某些Apple的应用程序会显示相同的错误。可以轻松查看是否有大标题,因为这样您就可以同时看到大标题和多余的标签:

在此处输入图片说明


fl0*_*034 6

我现在正在使用此解决方法,因为我希望我的大多数用户在搜索处于活动状态时可以看到导航栏(出于几个特定于 app-ux 的原因)。

var isIosVersionWithNavigationBarBug: Bool {
    if #available(iOS 13.2, *) {
        return false
    }
    if #available(iOS 13.0, *) {
        return true
    }        
    return false
}
Run Code Online (Sandbox Code Playgroud)

在我的搜索控制器中,我像这样使用它

mySearchController.hidesNavigationBarDuringPresentation = isIosVersionWithNavigationBarBug
Run Code Online (Sandbox Code Playgroud)

因此,如果 iOS 13.2 正在发布并且用户对其进行更新,则该解决方法将不再适用。