Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

uinavigationcontroller - iOS 13 UIBarButtonItem not clickable and overlapping UINavigationBars when using UISearchController

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.

enter image description here

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here

And here's what it looks like afterwards:

enter image description here

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:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...