3

My view controller hierarchy is SWRevealViewController -> UINavigationViewController -> MyController1. MyController1 presents MyController2 using self.present. MyController2 is not within UINavigationViewController and presentation is modal (device is iPhone). In viewWillAppear of MyController2 I call self.setNeedsStatusBarAppearanceUpdate(), but preferredStatusBarStyle is never called by the system and status bar appearance remains same (as it was for MyViewController1). Am I missing something here?

EDIT

info.plist has View controller-based status bar appearance set to YES

peetonn
  • 2,942
  • 4
  • 32
  • 49
  • 1
    Possible duplicate of [preferredStatusBarStyle isn't called](http://stackoverflow.com/questions/19022210/preferredstatusbarstyle-isnt-called) – Nicolas Miari Apr 28 '17 at 05:13
  • yes, I looked through the whole thread. nothing helped. my controller is not inside `UINavigationController` as i mentioned – peetonn Apr 28 '17 at 15:55

3 Answers3

6

This is what worked for me in my VC...

self.modalPresentationCapturesStatusBarAppearance = true
Jesse S.
  • 783
  • 7
  • 11
4

in your info.plist

View controller-based status bar appearance make it YES

elk_cloner
  • 2,049
  • 1
  • 12
  • 13
4

Our issue was a container VC.

So had to tell it to allow the contained (visible) VC to call the shots:

final class ContainerVC: UIViewController {
  final var centerVC: UIViewController? // set to an OtherVC elsewhere

  override var childViewControllerForStatusBarHidden: UIViewController? {
    return centerVC
  }
  override var childViewControllerForStatusBarStyle: UIViewController? {
    return centerVC
  }
}

final class OtherVC: UIViewController {
  override var prefersStatusBarHidden: Bool {
    return true
  }
  override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
  }
  override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
    return .slide
  }
}
mcm
  • 655
  • 9
  • 10