如何在导航栏的模态视图中更改iOS 7中的UIStatusBarStyle? [英] How to change UIStatusBarStyle in iOS 7 in modal views with navigation bar?
问题描述
iOS 7 Transition Guide 提供了一个很好的提示如何在 UIViewController
中使用动态更改 UIStatusBarStyle
p>
The iOS 7 Transition Guide give a good hint how to change the UIStatusBarStyle
dynamically in a UIViewController
using
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
以及 [self setNeedsStatusBarAppearanceUpdate];
这在单个视图应用程序中工作正常。但是,我现在正在尝试将模态视图中的 UIStatusBarStyle
更改为 UIStatusBarStyleLightContent
。有一个 MainViewController
,它分隔到 ModalViewController
,它本身嵌入在 NavigationController
。 ModalViewController
已将其委托设置为 MainViewController
。
This works fine in a single view application. However, I'm now trying to change the UIStatusBarStyle
in a modal view to UIStatusBarStyleLightContent
. There is a MainViewController
which segues to the ModalViewController
, which itself is embedded in a NavigationController
. The ModalViewController
has set its delegate to the MainViewController
.
我试图在 ModalViewController $ c中调用
[self setNeedsStatusBarAppearanceUpdate];
$ c>以及该类中的以下方法没有效果:
I tried to call [self setNeedsStatusBarAppearanceUpdate];
in the ModalViewController
together with the following method in that class without effect:
// In ModalViewController.m
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
我还试图调用 [self setNeedsStatusBarAppearanceUpdate];
MainViewController
on prepareForSegue:sender:
方法,条件为 - (UIStatusBarStyle)preferredStatusBarStyle {}
在呈现模态视图时返回 UIStatusBarStyleLightContent
- 但也没有效果。
I also tried to call [self setNeedsStatusBarAppearanceUpdate];
in MainViewController
on prepareForSegue: sender:
method with conditions in - (UIStatusBarStyle)preferredStatusBarStyle {}
to return UIStatusBarStyleLightContent
when the modal view is presented - but that has no effects, too.
如何在模态视图中更改UIStatusBarStyle?
How can I change the UIStatusBarStyle in the modal view?
编辑:发布更新:我需要提到 ModalViewController
嵌入 NavigationController
并带有 NavigationBar
。将 NavigationBar
设置为隐藏到上面调用 [self setNeedsStatusBarAppearanceUpdate];
in ModalViewController
工作正常。但是当条形图可见时不是。
Post updated: I need to mention that the ModalViewController
is embedded in a NavigationController
with a NavigationBar
. With NavigationBar
set to hidden to above call of [self setNeedsStatusBarAppearanceUpdate];
in ModalViewController
works fine. But not when the Bar is visible.
推荐答案
您需要一个在Fullscreen中显示的ViewController才能返回相应的状态栏信息。在你的情况下:包含ModalViewController的NavigationController需要实现 preferredStatusBarStyle
并返回 UIStatusBarStyleLightContent
。
You need a ViewController that's showing in Fullscreen to return the appropriate status bar infos. In your case: The NavigationController which contains ModalViewController needs to implement preferredStatusBarStyle
and return UIStatusBarStyleLightContent
.
只有在视图控制器返回的值实际发生更改时,才需要调用 setNeedsStatusBarAppearanceUpdate
。首次显示视图控制器时,无论如何都会查询它们。
A call to setNeedsStatusBarAppearanceUpdate
is only necessary if the values a view controller returns actually change. When the view controller is first presented they are queried anyway.
这篇关于如何在导航栏的模态视图中更改iOS 7中的UIStatusBarStyle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!