0

I have a view controller that is embedded in a navigation controller and I am trying to show/hide status bar as well as navigation bar when a particular gesture is recognized.

Info.plist is set to Status bar style = UIStatusBarStyleLightContent and View controller-based status bar appearance = NO

private var statusbarhidden = false {
    didSet {
        setNeedsStatusBarAppearanceUpdate()
    }
}

override var prefersStatusBarHidden: Bool {
    return statusbarhidden
}

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
    return UIStatusBarAnimation.fade
}

@objc private func toggle(sender: UILongPressGestureRecognizer){
    statusbarhidden = !statusbarhidden
    self.navigationController?.setNavigationBarHidden(statusbarhidden, animated: true)
}

I tried changing View controller-based status bar appearance to YES in the info.plist and could not get this to work either. What am I missing here? Any help is appreciated.

Edit - OK I figured the exact hierarchy of ViewControllers. It is ViewController1 -> ViewController2 -> UINavigationController -> ViewController3

I need ViewController3 to show/hide the status bar and navigation bar. So I tried overriding childViewControllerForStatusBarHidden in ViewController1. But ViewController3 is nil when the system tries to query this value on app startup. Any idea how to fix this?

learner
  • 139
  • 1
  • 13
  • Review your exact hierarchy for [`childForStatusBarStyle`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621433-childforstatusbarstyle) – Orkhan Alikhanov May 15 '19 at 18:06
  • I edited the question. Can you please take a look? – learner May 15 '19 at 22:44
  • Override `childViewControllerForStatusBarHidden` in `ViewController1` to return its child `ViewController2`, do same in `ViewController2` to return `UINavigationController`. After that, all should work fine I believe. – Orkhan Alikhanov May 16 '19 at 00:14

0 Answers0