hide status bar swift 4

后端 未结 15 1850
无人及你
无人及你 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:27

    Use the following code UIApplication.shared.isStatusBarHidden = true

    this is the only thing that I found that is working in iOS11. you can write in didFinishLaunchingWithOptions or in 'viewWillAppear' of you BaseViewController Enjoy.

    0 讨论(0)
  • 2021-02-04 02:33

    Although some implementations are cleaner such as:

    UIApplication.shared.isStatusBarHidden = true

    There are some weird clipping animations during transitions. Although more verbose, I prefer @MachTurtle's solution:

    override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(true)
            if let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as? UIView{
            statusBar.isHidden = true
            }
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)
        let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
        statusBar.isHidden = false
    }
    

    Try it out, works great for me.

    0 讨论(0)
  • 2021-02-04 02:34

    I discovered that prefersStatusBarHidden wasn't being called in my view controller because I was using a custom container view and I needed to forward the status bar hiding responsibility to the child view controller. Implementing var childForStatusBarHidden: UIViewController? { return childViewController } in the container view controller fixed if for me.

    0 讨论(0)
  • 2021-02-04 02:34

    Add this to your info.plist

    <key>UIStatusBarHidden</key>
        <true/>
    
    0 讨论(0)
  • 2021-02-04 02:34

    I was searching for it and the one work for me is

    Swift 5

    override var prefersStatusBarHidden: Bool {
      return true
     }
    
    0 讨论(0)
  • 2021-02-04 02:35

    Try setting "View controller-based status bar appearance" flag in Info.plist to YES. This will force app to call prefersStatusBarHidden: Bool property on every view controller.

    0 讨论(0)
提交回复
热议问题