status bar hidden in modal view (over fullscreen presentation)

raphael picture raphael · Nov 5, 2015 · Viewed 16k times · Source

try to hide the status bar from a modal view.

already check several methods:

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

with / without self.setNeedsStatusBarAppearanceUpdate()

also

UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade)

but depreciated in iOS 9

this works in fullscreen presentation (modal segue presentation option) but note in over full screen which is my setting.

if you have any idea..

Answer

Womble picture Womble · Oct 18, 2016

For a non-fullscreen presentation of a View Controller, you need to use the modalPresentationCapturesStatusBarAppearance property.

e.g.

toViewController.modalTransitionStyle = .coverVertical
toViewController.modalPresentationStyle = .overFullScreen
toViewController.modalPresentationCapturesStatusBarAppearance = true

fromViewController.present(toViewController,
            animated: true,
            completion: nil)

For a fullscreen presentation of a View Controller, you need to:

  1. set the new VC's modalPresentationStyle.
  2. override prefersStatusBarHidden in the new VC
  3. set your app plist UIViewControllerBasedStatusBarAppearance value to YES

e.g.

toViewController.modalTransitionStyle = .coverVertical
toViewController.modalPresentationStyle = .fullScreen

fromViewController.present(toViewController,
            animated: true,
            completion: nil)

(Yes, status bar setting in iOS is pitifully bad. It's no wonder Stack Overflow has so many questions on the subject, and so many varied answers.)