0

There are two viewcontrollers.

Controller A with status bar. Controller B without status bar.

When I push A to B, there is still the status bar in B.

To hide the status bar in B. I set below in B.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    UIApplication.shared.isStatusBarHidden = true
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    UIApplication.shared.isStatusBarHidden = false
}

I have tried to set the prefersStatusBarHidden to true, but it failed. When I use present, there is no status bar in B.

Do you know the reason why it doesn't work? What's wrong with the codes? Thanks in advance.

Malik
  • 3,763
  • 1
  • 22
  • 35
Leaf
  • 203
  • 1
  • 2
  • 13

1 Answers1

0

override this method in your ViewController B

override var prefersStatusBarHidden: Bool {
    return true
}

override same method in your ViewController A

override var prefersStatusBarHidden: Bool {
    return false
}

Include this in your plist file.

View controller-based status bar appearance" flag in Info.plist to YES

Muhammad Shauket
  • 2,643
  • 19
  • 40