hide status bar swift 4

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

提交回复
热议问题