prefersStatusBarHidden and navigation bar anomalies

While presenting a modal view controller - that uses AVFoundation to capture a still image - i chose to hide the status bar as follows:


override prefersStatusBarHidden: Bool {
   return true
}


The presenting view controller is a regular view controller inside a UINavigationController.


This works beautifully. However, once the modal view controller is dismissed, the status bar starts overlapping the navigation bar on the underlying view controller. Attempts to call setNeedsStatusBarAppearanceUpdate() prove futile. Furthermore, when going back to previous view controllers in the navigation controller stack, all view controllers exhibit the same behavior: the status bar is overlapping the navigation bar, it's as if the navigation bar is unaware the status bar is visible.


This behavior was observed on both iOS 9.x and 8.x, but appears to work just fine in iOS 10. After several tries to resolve the issue, i stumbled upon a workaround that appears to work but feels jenky: Setting the modalPresentationStyle to .overCurrentContext gets the behavior you expect on iOS 9 and 8, but screws up iOS 10 (the status bar is never hidden).


i don't understand why setting the modalPresentationStyle causes it work, and would love to hear an explanation or a cleaner workaround.


- number4

Hi,


I think this is a bug in iOS 9 at least ( maybe below). I use a simmilar workaround when presenting an UINavigationController inside a custom view controller. The presenting works fine but when it gets dismissed the then reappearing viewControllers are missplaced.

And using UIModalPresentationOverCurrentContext is the only workaround I found. The main idfference is that the viewController which become hidden on presentation are not removed from the view hierachy. The side effect is, that they don't receive a view(Will/Did)Disappear: message on presentation and of course no view(Will/Did)Appear:.


So my code looks like:

        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0"))
        {
            navController.modalPresentationStyle = UIModalPresentationCurrentContext;
        }
        else
        {
            navController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        }


You may want to file a bugreport to check if this is a know issue.


Dirk

prefersStatusBarHidden and navigation bar anomalies
 
 
Q