2

Background: I implemented a Custom UIViewController Transition where the first view controller (VC1) has a visible status bar

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

while the second presented view controller (VC2) has a hidden status bar:

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

Transitioning is controlled by the user since I implemented a pull to open transition with gesture controllers.

Objective: I want the status bar to be hidden during appearance transition AND disappearance transition (essentially like the Google Maps Slide Out Menu).

Problem: The status bar is correctly hidden during the entire appearance transition of ViewController VC2. But during the entire disappearance transition the status bar is visible. Any suggestions on how to properly implement this for iOS 9?

fsb
  • 290
  • 10
  • 28
ddxue
  • 21
  • 3

2 Answers2

0

Just try to set status bar hidden on viewWillAppear and viewWillDisappear function.

Srj0x0
  • 458
  • 3
  • 12
  • When I use override `func prefersStatusBarHidden() -> Bool { return shouldHideStatusBar }` and set `shouldHideStatusBar = true; self.setNeedsStatusBarAppearanceUpdate();` in **viewWillAppear** and **viewWillDisappear** it doesn't help me control the status bar appearance _during_ the transition (Info.plist set with View controller-based status bar appearance = YES). – ddxue May 18 '16 at 08:47
0

You can create an instance var to hold the status bar hidden state and return this boolean from prefersStatusBarHidden(). When this value changes, call setNeedsStatusBarAppearanceUpdate().

For example:

var statusBarHidden = true {
    didSet {
        if oldValue != statusBarHidden {
            setNeedsStatusBarAppearanceUpdate()
        }
    }
}

override var prefersStatusBarHidden: Bool {
    return statusBarHidden
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    statusBarHidden = false
}
Harry Bloom
  • 2,359
  • 25
  • 17