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
  • 375
  • 3
  • 13

3 Answers3

0

you can try this code ...:)

override var prefersStatusBarHidden: Bool {
    return true
}
Shivam Parmar
  • 1,520
  • 11
  • 27
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
  • 427
  • 6
  • 24
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
  • 1,078
  • 1
  • 8
  • 30