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

女生的网名这么多〃 提交于 2019-12-03 16:15:53

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/57784596/how-to-prevent-gap-between-uinavigationbar-and-view-in-ios-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!