iosuinavigationcontrolleruinavigationbaruisearchcontrollerpushviewcontroller

Grey background in navigation bar with searchController added to navigationItem during push


I have a table view in navigation controller so that I can push the detail view controller on the stack. It works fine, until I add a search controller to the navigation item, like so:

searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.delegate = self
searchController.searchBar.tintColor = Colors.mlLabel
navigationItem.searchController = searchController
definesPresentationContext = true

It results in temporary grey background, see below:

enter image description here

When debugging the view hierarchy, it looks like UIViewControllerWrapperView's _UIParallaxDimmingView(selected below) is causing this, as both navigation bar and status bar are transparent.

enter image description here

How can I fix this?

Note: Setting the animated property in pushViewController() to false works, but I'd like to keep the animation.

Update: This seems to be issue only on iOS 13. Probably from some recent version even, as I didn't have this issue earlier.

Update 2: I've noticed the same issue on multiple places in my app now, and it's not just in combination with SearchController. Basically the _UIParallaxDimmingView sticks its nose out.


Solution

  • I've finally found a solution. One of the problems was that I've set a background color for the navbar like so:

    UINavigationBar.appearance().backgroundColor = .white
    

    So removing the above line and adding the below line to the view controller being pushed fixed it.

    extendedLayoutIncludesOpaqueBars = true