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

后端 未结 2 1379
-上瘾入骨i
-上瘾入骨i 2021-02-02 09:33

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:

相关标签:
2条回答
  • 2021-02-02 10:24
    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.

    0 讨论(0)
  • 2021-02-02 10:31

    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()
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题