【发布时间】:2015-10-18 02:25:00
【问题描述】:
我有一个自定义 UIPresentationController 并覆盖 frameOfPresentedViewInContainerView 以进行自定义 viewController 演示。一切正常,除了状态栏。
我根本不希望状态栏改变外观——它应该保持原来的样子。现在 Apple 文档:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/modalPresentationCapturesStatusBarAppearance 说如果 modalPresentationStyle 不是 UIModalPresentationFullScreen 或 modalPresentationCapturesStatusBarAppearance 是 NO,我应该没问题,状态栏不应该改变。
使用此代码:
- (BOOL)prefersStatusBarHidden {
NSLog(
@"prefersStatusBarHidden was called %d %ld",
self.modalPresentationCapturesStatusBarAppearance,
(long)self.modalPresentationStyle
);
return YES;
}
我可以看到调用了 prefersStatusBarHidden,即使 modalPresentationCapturesStatusBarAppearance 为 NO(显示为 0)并且 modalPresentationStyle 为 UIModalPresentationCustom(显示为 4)。
显然,这就是在呈现 viewController 时状态栏发生变化的原因。
但是为什么呢?
我的想法是 iOS 认为 viewController 是全屏显示的,即使它不是。
我发现了 UIPresentationController 的属性 shouldPresentInFullscreen——它默认返回 YES。返回 NO 根本没有帮助,所以我不明白该属性甚至做了什么......它实际上没有任何效果。这同样适用于presentationStyle 属性——更改它时我看不到任何效果。我本来希望presentationStyle 属性被“重定向”到viewControllers modalPresentationStyle 属性,但它停留在UIModalPresentationCustom,它必须首先启动自定义演示。
所以,我的问题是:有人知道如何使用自定义 UIPresentationController 保持状态栏不变 - 有人可以解释一下 shouldPresentInFullscreen 和presentationStyle 属性吗?
谢谢! :)
【问题讨论】:
-
你有没有解决过这些问题?我还试图让 UIPresentationController 不显示全屏(实际上我希望能够与一些底层视图元素进行交互——比如标签栏)。我不知道如何让它给我一个不是窗口根视图控制器的presentingViewController。
-
不,遗憾的是我从来没有弄清楚:(
-
看起来这在 iOS 10 中已修复。我在这里为 iOS 9 提出了一个骇人听闻的解决方案:stackoverflow.com/questions/34819013/…
标签: ios uiviewcontroller uistatusbar uimodalpresentationstyle uipresentationcontroller