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

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

问题描述

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

var searchController: UISearchController!覆盖 func viewDidLoad() {super.viewDidLoad()标题=测试"tableView.delegate = 自我tableView.dataSource = 自我searchController = UISearchController(searchResultsController: nil)导航项.searchController = 搜索控制器//这会导致错误searchController.hidesNavigationBarDuringPresentation = falsenavigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(leftTapped))navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(rightTapped))}

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

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

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

当我使用 hidesNavigationBarDuringPresentation = true 时,它按预期工作.

<小时>

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

这是整个测试项目:

这是之后的样子:

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

编辑顺便说一句,我认为 Apple 的一些应用程序显示了相同的错误.更容易查看您是否有大标题,因为这样您就可以同时看到大标题和额外标签:

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.

  • Issue 1: The bar buttons are not reacting to touch except when I touch the outer most pixels of the screen (only possible with the simulator and mouse clicks).

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

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


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

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?


Update 1: Bug is still there in iOS 13.1.1


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:

And here's what it looks like afterwards:

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.

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天全站免登陆