Navigation bar gets blocked after pressing Cancel in UISearchController

848 Views Asked by At

I`m preparing app for iOS 13, and get bug with search controller in navigation bar. How to solve navigation bar glitch?

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

enter image description here

Press Cancel and navigation bar items becomes untouchable. Pushing view controller leads to navigation bar item overlap.

enter image description here

I have created test project on git https://github.com/eKroman/TESTsearchBar

Bug appears on iOS 13 beta (tested on iPad) using from Xcode 11 from beta 7 (maybe older beta) to Xcode 11 GM seed 2. Does not appear on simulators.

3

There are 3 best solutions below

1
On BEST ANSWER

I encountered the same problem, if I cancel the searchBar and change the navigationItem.title then I have a double title . It's like a ghost layer of the navigation bar stays here in the navigation controller.

This is how I fixed it:

searchController.hidesNavigationBarDuringPresentation = true

Probably best to use it until Apple fix this issue.

I also noticed that the back button switch to default color (blue), as if the navigationBar TintColor was reset.

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

0
On

For the back button reset to default color (blue) in @CoachThys's answer, I manage to work around it by the code below.

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
}

However, I cannot find a way to work around the back indicator image which is still reset to blue color briefly.

0
On

Add custom backbutton with a image would fixed the new bug. It works well for me.

        let negativeSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        negativeSpacer.width = -8
        self.navigationItem.leftBarButtonItems = [negativeSpacer, leftBarButtonItem]