iOS 13 nav bar not fitting to content

Viewed 1079

I've encountered an issue with the nav bar in iOS 13 when making it transparent. I have a navigation bar that I show and hide when a view controller appears/disappears.

When I pop the navigation controller and show the navigation bar again the background image and shadow image are not filling all of the nav bar's contents.

As you can see from the image I have search bar in the navigation bar that is derived from a UISearchController.

Here is the code for showing/hiding the nav bar:

extension UINavigationController {
    public func showTransparentNavigationBar() {
        navigationBar.setBackgroundImage(UIImage(), for: .default)
        navigationBar.shadowImage = UIImage()
    }

    public func hideTransparentNavigationBar() {
        navigationBar.setBackgroundImage(nil, for: .default)
        navigationBar.shadowImage = nil
    }
}

These methods are being called on the viewDidAppear of the initial view controller and pushed view controller.

How can I fix this issue?

enter image description here

1 Answers

For me, the solution was to set extendedLayoutIncludesOpaqueBars to true in the ViewController that contains the SearchBar.

Related