UIViewController's prefersStatusBarHidden not working

前端 未结 4 595
星月不相逢
星月不相逢 2020-12-23 11:21

I am trying to make the status bar for one of my view controllers to be hidden (when displayed modally). When I\'m presenting the view controller, the status bar is is to be

4条回答
  •  忘掉有多难
    2020-12-23 11:50

    If it's not working and your UIViewController is a child in UINavigationController, then this code might be a solution for you.

    open override var prefersStatusBarHidden: Bool {
        return topViewController?.prefersStatusBarHidden ?? super.prefersStatusBarHidden
    }
    

    Basically the UINavigationController uses it's own prefersStatusBarHidden value, but in my case I wanted to overwrite that by its top view controller's property in hierarchy.

提交回复
热议问题