Navigation bar overlap status bar after push

Viewed 158

Structure: NavigationController -> VC1 -> VC2

VC1 needs to show or hide status bar programmatically, it's controlled by statusBarHidden

var statusBarHidden = false {
        didSet {
            setNeedsStatusBarAppearanceUpdate()
        }
    }
    
    override var prefersStatusBarHidden : Bool {
        return false
    }

VC2 also added the following code:

    override var prefersStatusBarHidden : Bool {
        return false
    }

If statusBarHidden is not changed before self.navigationController?.pushViewController(VC2, animated: true), status bar WILL NOT overlap navigation bar in VC2.

But once statusBarHidden is set to true, even it is set back to false, status bar will overlap navigation bar in VC2, BTW, it's the same with Storyboard Segue. But it works fine on iPhones with notch, such as iPhone X, iPhone 11.

enter image description here

I had tried to set a fix height, but the actual height seemed to be not effected, navigation bar always kept a certain height than 64.

navBar.frame = CGRect(x:0, y:20, width:self.view.frame.size.width, height:64)
0 Answers
Related