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

后端 未结 2 1387
-上瘾入骨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: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()
            }
        }
    }
    

提交回复
热议问题