Leon Lucardie
Leon Lucardie

Reputation: 9730

How to prevent gap between uinavigationbar and view in iOS 13?

We are currently having an issue with navigation bar sizing when using modal presentation in iOS 13.

In most cases this works fine as can be seen in this screenshot:

However, in a few screens we get this weird effect, with the navigation bar having a lower height and a weird "see-through" gap between it and the view. As seen in this screenshot:

Both of the view controllers have the same values set for their properties, are modally presented and have the same constrains on their subviews (0 spacing from the superview/margins/top layout guide).

This issue doesn't happen in iOS 12, even when built with the iOS 13 SDK. Is this a known issue in iOS 13 (beta 8), or is there something we should adjust in the code/storyboard?

Upvotes: 28

Views: 4911

Answers (3)

ItsAlwaysThere
ItsAlwaysThere

Reputation: 109

In case these answers don't work make sure to set the navigation bar type to "Standard".

Upvotes: 0

Jakehao
Jakehao

Reputation: 1019

Like Rod's answer, but I found it only works if I put setNeetsLayout() in next main thread runLoop:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Workaround for iOS 13 modal gap below navigationbar
    if #available(iOS 13.0, *) {
        DispatchQueue.main.async {
            self.navigationController?.navigationBar.setNeedsLayout()
        }
    }
}

Upvotes: 19

Rod
Rod

Reputation: 779

override func viewWillAppear(_ animated: Bool) {  
    super.viewWillAppear(animated)  
    if #available(iOS 13.0, *) {  
        navigationController?.navigationBar.setNeedsLayout()  
    }
}  

We found this work around here and it worked for us.

Upvotes: 31

Related Questions