Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

status bar hidden in modal view (over fullscreen presentation)

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..

like image 350
raphael Avatar asked Nov 05 '15 14:11

raphael


2 Answers

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.)

like image 159
Womble Avatar answered Sep 28 '22 04:09

Womble


To hide the status bar when doing an over full screen modal, you need to set this in viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()    
    modalPresentationCapturesStatusBarAppearance = true
}

Then do the standard method to hide status bar:

override var prefersStatusBarHidden: Bool {
    return true
}
like image 25
bnussey Avatar answered Sep 28 '22 06:09

bnussey