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

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.


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()
        }
    }
}