status bar hidden in modal view (over fullscreen presentation)
Asked Answered
E

4

18

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

Emergency answered 5/11, 2015 at 14:3 Comment(4)
Please check #32809093, which I think addresses your issue.Infamous
hi, thanks but same issue. works on full screen presentation but not on over full screen setting..Emergency
First go to plist and check if View controller-based status bar appearance is set to YES and set prefersStatusBarHidden() which you've tried.Arne
same issue, but thanks.Emergency
H
58

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

Hoecake answered 18/10, 2016 at 0:53 Comment(2)
Is .coverVertical necessary?Fons
No, it's the default valueMemo
A
8

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
}
Appoint answered 23/3, 2018 at 7:18 Comment(0)
S
2

Indeed for FullScreen status bar update called automatically, but not for OverFullScreen.

Furthermore in my case i was need to deal with navigation controller in stack, to pass ModalViewController as child:

extension UINavigationController {

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

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

Inside ModalViewController we manually update status bar, also in order to make it smooth we have to do that in viewWillDisappear, but at that point visibleViewController still ModalViewController, nothing left as to use internal bool statusBarHidden 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
}
Scot answered 7/11, 2015 at 13:9 Comment(0)
C
0

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

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
}
Cloistered answered 20/1, 2017 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.