How do I use modalPresentationCapturesStatusBarAppearance = NO with a custom UIPresentationController?

I have a custom UIPresentationController and override frameOfPresentedViewInContainerView for a custom presentation viewController. Everything works fine except for the status bar.

I don't want the status bar to change its appearance at all - it should just stay, but it looked before. Now Apple Documentation: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/modalPresentationCapturesStatusBarAppearance says that if there is no modalPresentationFodaltyle Script is not I should be fine and the status bar should not change.

With this code:

- (BOOL)prefersStatusBarHidden {
    NSLog(
        @"prefersStatusBarHidden was called %d %ld",
        self.modalPresentationCapturesStatusBarAppearance,
        (long)self.modalPresentationStyle
    );

    return YES;
}

      

I can see that prefersStatusBarHidden gets called even if modalPresentationCapturesStatusBarAppearance is NO (displayed as 0) and modalPresentationStyle is UIModalPresentationCustom (displayed as 4).

Obviously the reason why the status bar changes when the viewController is presented.

But why?

My thought on this is that iOS thinks the viewController is presented in full screen mode even if it isn't.

I discovered the UIPresentationController property shouldPresentInFullscreen - it returns YES by default. Returning NO doesn't help at all, so I don't understand what this property even does ... It has no effect. The same goes for the presentationStyle property - I don't see any effect when it changes. I would expect the presentationStyle property to be "redirected" to the viewControllers modalPresentationStyle property, but this will remain in the UIModalPresentationCustom, which should be to initiate a custom presentation first.

So my questions are, does anyone know how to simply keep the status bar the same as with a custom UIPresentationController - and can anyone explain the shouldPresentInFullscreen and presentationStyle properties?

Thank!:)

+3


source to share


1 answer


Try to implement childViewControllerForStatusBarStyle: and return null for it in the class calling your UIPresentationController, usually UINavigationController.

This is what I do in Swift when I don't want the child VC to interfere with my judiciously chosen status bar style:

override func childViewControllerForStatusBarStyle() -> UIViewController? {
    return nil // ignore childs and let this Navigation Controller handle the StatusBar style
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent // or .Default depending on your Style
}

      



This requires iOS8 or newer and can only be used if you install the key UIViewControllerBasedStatusBarAppearance

in Info.plist

to YES

.

Bonus: if it doesn't help the caller use it in the shown Ccontroller. I checked my projects, in one of them it is also in NavigationController shown as PopOver and is working fine as of today.

0


source







All Articles