Status bar hidden in modal view (above full screen view)

try to hide the status bar from the modal view.

already check out several methods:

override func prefersStatusBarHidden() -> Bool { return true } with / without self.setNeedsStatusBarAppearanceUpdate() 

and

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

but depreciates in iOS 9

this works in full screen (modal segue presentation option), but pay attention to the full screen, which is my setting.

if you have any ideas ..

+6
source share
4 answers

To present a not full-screen view of the view controller, you need to use the modalPresentationCapturesStatusBarAppearance property.

eg.

 toViewController.modalTransitionStyle = .coverVertical toViewController.modalPresentationStyle = .overFullScreen toViewController.modalPresentationCapturesStatusBarAppearance = true fromViewController.present(toViewController, animated: true, completion: nil) 

To present a full-screen view of a view controller, you need to:

  • install the new VC modalPresentationStyle .
  • override prefersStatusBarHidden in new VC
  • set app plist UIViewControllerBasedStatusBarAppearance to YES

eg.

 toViewController.modalTransitionStyle = .coverVertical toViewController.modalPresentationStyle = .fullScreen fromViewController.present(toViewController, animated: true, completion: nil) 

(Yes, setting the status bar in iOS is unfortunate. It's no wonder that Qaru has so many questions on this and so many varied answers.)

+30
source

Valid for updating the FullScreen status FullScreen automatically, but not for OverFullScreen .

Also, in my case, I needed to deal with the navigation controller on the stack in order to pass the ModalViewController as a child:

 extension UINavigationController { public override func childViewControllerForStatusBarHidden() -> UIViewController? { return self.visibleViewController } public override func childViewControllerForStatusBarStyle() -> UIViewController? { return self.visibleViewController } } 

Inside ModalViewController we manually update the status bar to make it smooth, we have to do it in viewWillDisappear , but at this point visibleViewController still ModalViewController >, there is nothing left to use the internal status of boolBarHidden and update it accordingly.

 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.statusBarHidden = true self.setNeedsStatusBarAppearanceUpdate() } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) self.statusBarHidden = false self.setNeedsStatusBarAppearanceUpdate() } override func prefersStatusBarHidden() -> Bool { return self.statusBarHidden } 
+1
source

If you use a storyboard and want to hide / show the status bar, you can use this method on the previous view controller:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none) } 
0
source

To hide the status bar when executing a full-screen modal value, you need to set this in viewDidLoad:

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

Then follow the standard method to hide the status bar:

 override var prefersStatusBarHidden: Bool { return true } 
0
source

All Articles