1

I used the following code to hide the status bar and it works fine But it works until I go to another page. That is, if I go to another page and go back, it won't work anymore Does anyone know why? Can anyone help me?

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.hidesBarsOnSwipe = true
    }
    override var prefersStatusBarHidden : Bool {
        if self.navigationController?.isNavigationBarHidden == true {
            return true
        } else {
            return false
        }
    }
Sayooj
  • 345
  • 3
  • 12

3 Answers3

0

you can try this code ...:)

override var prefersStatusBarHidden: Bool {
    return true
}
Shivam Parmar
  • 1,411
  • 9
  • 26
0

just add this one

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// call this func to force preferredStatusBarStyle to be read again.
setNeedsStatusBarAppearanceUpdate()}
Govind Rakholiya
  • 407
  • 5
  • 22
0
  • You can hide it from info.plist with option initially hides status bar giving value true

this will hide status bar for your entire app

  • Then show it to the specific viewcontrollers with following code

    override var prefersStatusBarHidden: Bool {
    return false
    }
    
Nayan Dave
  • 918
  • 1
  • 8
  • 26