启动时无法隐藏状态栏 [英] Can't hide status bar on launch
问题描述
我正在使用水平
页面导航构建一个 iOS 9
应用程序,需要在某些页面上显示状态栏页面,并将其隐藏在其他页面上。我想使用淡入/淡出动画,所以我必须设置
I'm building an iOS 9
app with horizontal
pages navigation and need to show the status bar on some pages, and hide it on others. I want to use the fade in/out animation so I have to set
查看基于控制器的状态栏外观=否
并更新状态栏,如下所示:
and update the status bar like this:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
这个程序在页面之间导航时效果很好,但我无法摆脱状态栏启动。
This procedure works perfectly when navigating between pages, but I can't get rid of the status bar on launch.
我试过设置:状态栏最初隐藏= YES
将此添加到 NavigationControllers viewDidLoad:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];
将此添加到AppDelegates didFinishLaunchingWithOptions:
Adding this to AppDelegates didFinishLaunchingWithOptions:
application.statusBarHidden = YES;
将此添加到初始页面的ViewController:
Adding this to the ViewController of the initial page:
- (BOOL)prefersStatusBarHidden {
return YES;
}
检查常规 - >部署信息中的隐藏状态栏选项
Checking the "Hide status bar" option in General->Deployment Info
并在链接的情节提要元素中将状态栏设置为无
And setting "Status Bar" to "None" in the linked storyboard element
但状态栏仍显示发射。如何在不更改的值的情况下摆脱启动时的状态栏查看基于控制器的状态栏外观
?
But the status bar is still showing up on launch. How can I get rid of the status bar on launch without changing the value of View controller-based status bar appearance
?
推荐答案
原来我做的是正确的,但是有一个错误的 [[UIApplication sharedApplication] setStatusBarHidden:NO];
埋葬在继承的代码中。我抓了它,但忽略了这一行......
Turns out what I was doing was correct, but there was an errant [[UIApplication sharedApplication] setStatusBarHidden:NO];
buried in inherited code. I grepped it, but overlooked that line...
(使用 git grep StatusBar
查找代码行改变状态栏的git仓库)
(use git grep StatusBar
to find lines of code in a git repo that mutate the status bar)
此外,唯一需要的代码是:
Also, the only code needed is:
查看基于控制器的状态栏外观=否
(在plist中)
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
状态栏需要更新的地方(通常在 viewWillAppear
)
anywhere the status bar needs updating (usually in viewWillAppear
)
这篇关于启动时无法隐藏状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!