使用UISearchController时,iOS 13 UIBarButtonItem不可单击且UINavigationBars重叠 [英] iOS 13 UIBarButtonItem not clickable and overlapping UINavigationBars when using UISearchController

查看:64
本文介绍了使用UISearchController时,iOS 13 UIBarButtonItem不可单击且UINavigationBars重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导航栏,其中包含一些UIBarButtonItem按钮和一个像这样连接的UISearchBar

I got a navigation bar containing some UIBarButtonItem buttons and a UISearchBar hooked up like this

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))
}

场景:我进入搜索栏,然后点击取消.

Scenario: I tap into the search bar and tap cancel afterwards.

  • 问题1:除了我触摸屏幕最外面的像素时(只有通过模拟器和鼠标单击才有可能),条按钮对触摸没有反应.

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

Issue 2: The navigation items are overlapping when I push another view controller.

当我使用hidesNavigationBarDuringPresentation = true时,它的工作与预期的一样.

When I use hidesNavigationBarDuringPresentation = true it's working like expected.

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

The issue appears on notched and non-notched iPhones iOS 13.0 and 13.1 using Xcode 11.0 and 11.1.

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

Here's the whole test project: https://github.com/fl034/HidesNavigationBarDuringPresentationTest

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

I've filed a radar (and you should too), but maybe some of you guys have already a workaround for it?

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

Update 1: Bug is still there in iOS 13.1.1

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

Update 2: Bug is fixed in iOS 13.2 beta (thanks @Ben Gomm)

推荐答案

视图调试器揭示了此错误的原因.导航栏的内容正在复制.在显示搜索之前,导航栏是这样的:

The view debugger reveals what's going on with this bug. The contents of the navigation bar are being copied. Here's what the navigation bar looks like before you show the search:

这是之后的样子:

两个复制视图和额外的UILabel就是问题所在.我不知道他们在做什么,也找不到删除它们的方法.

The two replicant views and the extra UILabel are the problem. I don't know what they're doing there and I can't find a way to remove them.

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

EDIT By the way, I think some of Apple's apps display the same bug. It's easier to see if you have large titles, because then you can see the large title and the extra label at the same time:

这篇关于使用UISearchController时,iOS 13 UIBarButtonItem不可单击且UINavigationBars重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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