hide status bar swift 4

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

    You probably found your own solution to this already, but I got it working this way:

    override func viewWillAppear(_ animated: Bool) {
        // Sets the status bar to hidden when the view has finished appearing
        let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
        statusBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        // Sets the status bar to visible when the view is about to disappear
        let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
        statusBar.isHidden = false
    }
    

提交回复
热议问题