如何在自定义UIPresentationController中使用modalPresentationCapturesStatusBarAppearance = NO? [英] How to use modalPresentationCapturesStatusBarAppearance = NO with a custom UIPresentationController?

查看:1282
本文介绍了如何在自定义UIPresentationController中使用modalPresentationCapturesStatusBarAppearance = NO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义UIPresentationController,并为自定义viewController演示覆盖了frameOfPresentedViewInContainerView.除了状态栏,一切正常.

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

我根本不希望状态栏改变外观-它应该保持原样,但它看起来像以前一样.现在是Apple文档: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/modalPresentationCapturesStatusBarAppearance 表示modalPresentationStyle不是UIModalPresentationFullScreen或modalPresentationCapears is,我应该没事,状态栏也不应更改.

I do not want the status bar to change appearance at all – it should just stay however it looked before. Now the Apple Documentation: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/modalPresentationCapturesStatusBarAppearance says if modalPresentationStyle is not UIModalPresentationFullScreen OR modalPresentationCapturesStatusBarAppearance is NO, i should be fine and the status bar should not change.

使用以下代码:

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

    return YES;
}

我看到即使modalPresentationCapturesStatusBarAppearance为NO(显示为0)并且modalPresentationStyle为UIModalPresentationCustom(显示为4),preferredStatusBarHidden也会被调用.

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

很明显,这就是在显示viewController时状态栏发生更改的原因.

Obviously, that's the reason the status bar changes when presenting the viewController.

但是为什么?

我对此的想法是,iOS认为viewController是全屏显示的,即使它不是.

My thought on this is that iOS thinks that the viewController is presented in fullscreen even though it is not.

我发现UIPresentationController的属性shouldPresentInFullscreen –默认情况下返回YES.返回NO根本没有帮助,所以我什至不了解该属性的作用……它实际上没有任何作用.这同样适用于presentationStyle属性–更改它时看不到任何效果.我本来希望将presentationStyle属性重定向"到viewControllers modalPresentationStyle属性,但是它停留在UIModalPresentationCustom上,它必须首先启动自定义表示.

I discovered UIPresentationController's property shouldPresentInFullscreen – it returns YES by default. Returning NO doesn't help at all, so i don't understand what that property even does... It has literally no effect. The same applies to the presentationStyle property – I don't see any effect when changing it. I would have expected the presentationStyle property to be "redirected" to the viewControllers modalPresentationStyle property, but that stays at UIModalPresentationCustom, which it has to be to initiate the custom presentation in the first place.

所以,我的问题是:是否有人知道如何使用自定义UIPresentationController保持状态栏不变?有人可以解释shouldPresentInFullscreen和presentationStyle属性吗?

So, my questions are: Does anybody know how to just keep the status bar as it is with a custom UIPresentationController – and can somebody explain the shouldPresentInFullscreen and presentationStyle properties?

谢谢! :)

推荐答案

尝试实现childViewControllerForStatusBarStyle:并在调用UIPresentationController(通常为UINavigationController)的类中为其返回nil.

Try implementing childViewControllerForStatusBarStyle: and return nil for it in the class invoking your UIPresentationController, usually a UINavigationController.

当我不希望孩子的VC干扰我明智选择的状态栏样式时,这就是我在Swift中所做的事情:

This is what I do in Swift when I don't want a child VC to interfere with my wisely 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
}

这需要iOS8和更高版本,并且仅在将Info.plist中的键UIViewControllerBasedStatusBarAppearance设置为YES时可用.

This requires iOS8 and newer and is only usable if you are setting the key UIViewControllerBasedStatusBarAppearance in your Info.plist to YES.

奖金:如果这对调用者没有帮助,请在显示的Ccontroller中使用它.我检查了我的项目,在其中一个项目中,它也在NavigationController中显示为PopOver,并且到目前为止运行良好.

Bonus: If this does not help in the caller, use it in the shown Ccontroller. I checked my projects, in one of them it's also in the NavigationController shown as PopOver and working fine as of today.

这篇关于如何在自定义UIPresentationController中使用modalPresentationCapturesStatusBarAppearance = NO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆