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?