hide status bar swift 4

后端 未结 15 1854
无人及你
无人及你 2021-02-04 01:51

I am trying to hide status bar in one of my UIViewControllers (Swift 4).

  • Firstly, I set View controller-based status bar appearance to

15条回答
  •  臣服心动
    2021-02-04 02:41

    You can hide the status bar in any or all of your view controllers just by adding this code:

    override var prefersStatusBarHidden: Bool {
         return true
       }
    

    Any view controller containing that code will hide the status bar by default.

    If you want to animate the status bar in or out, just call setNeedsStatusBarAppearanceUpdate() on your view controller – that will force prefersStatusBarHidden to be read again, at which point you can return a different value. If you want, your call to setNeedsStatusBarAppearanceUpdate() can actually be inside an animation block, which causes the status bar to hide or show in a smooth way.

提交回复
热议问题