How to hide status bar of a single view controller in iOS 9?

后端 未结 15 1238
挽巷
挽巷 2020-12-13 06:15

In a ViewController, which I presented modally, I did this:

override func prefersStatusBarHidden() -> Bool {
    return true
}

This used

15条回答
  •  时光取名叫无心
    2020-12-13 06:46

    In your UIViewController:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        UIApplication.shared.isStatusBarHidden = true
    }
    
     override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        //It will show the status bar again after dismiss
        UIApplication.shared.isStatusBarHidden = false
    }
    
    override var prefersStatusBarHidden: Bool {
        return true
    }
    

提交回复
热议问题