我正在展示一个带有交互式关闭过渡的模态 UINavigationController
。父 View Controller 有一个深色状态栏,模态视图 Controller 有一个浅色状态栏。我正在使用基于 iOS 7 View Controller 的状态栏外观配置。
只要我以非交互方式呈现和关闭 View Controller ,一切都可以正常工作。但是,当我开始交互式关闭过渡并取消它时,状态栏颜色仍然是黑色。
我创建了一个 sample project .点击“菜单”按钮,然后从屏幕右边缘平移开始交互式过渡。
我尝试过的事情:
- 在取消转换后,在涉及的任何导航和 View Controller 上调用
-setNeedsStatusBarAppearanceUpdate
- 将 navigationBar.barStyle 更改为
UIBarStyleDefault
并返回到UIBarStyleBlack
我还验证了我的模态导航 Controller 的 statusBarStyle 设置是否正确:
(lldb) p (UIStatusBarStyle) [[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentedViewController] preferredStatusBarStyle]
(UIStatusBarStyle) $8 = UIStatusBarStyleLightContent
仍然,状态栏是黑色的。
还有什么想法可以尝试吗?
最佳答案
对我来说,这看起来像是 UINavigationController
中的错误 (rdar://15902745)。在取消关闭后,UINavigationController
不会再次查询其 presentedViewController
以获取 preferredStatusBarStyle
,而是使用其自身的 preferredStatusBarStyle
。我通过覆盖 -childViewControllerForStatusBarStyle
解决了这个问题:
- (UIViewController*)childViewControllerForStatusBarStyle {
if (self.presentedViewController) {
return self.presentedViewController.childViewControllerForStatusBarStyle;
}
return [super childViewControllerForStatusBarStyle];
}
然后,为了在解雇期间(而不是之后)动画更改,我还覆盖了 -preferredStatusBarStyle
。
我将解决方法推送到 sample project .
关于ios - 交互式 View Controller 解雇和更改 statusBarStyle 不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21336410/