在特定的视图控制器中隐藏状态栏,在TabbarViewController中
我有TabbarViewController
。在一个选项卡中,当导航到特定的ViewController
(详细图片视图)时,我想隐藏状态栏。 我已阅读此链接: How to hide a status bar in iOS?在特定的视图控制器中隐藏状态栏,在TabbarViewController中
但于我而言,这是行不通的,因为我不想躲藏在整个应用程序的状态栏,但只是在一个特定的ViewController
。
是否有一种方法可以在某个标签中隐藏滚动条?
*编辑: 我想隐藏状态栏的ViewController是一个PageViewController。这是问题吗?
试试下面的代码:
- (void) viewWillAppear:(BOOL)animated{
[UIApplication sharedApplication].statusBarHidden = YES;
}
谢谢。我试过了,但它仍然不起作用 – user2951346 2015-02-09 12:10:37
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
else{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown){
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
else{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
谢谢,但它仍然不起作用。而我想隐藏状态栏的ViewController是一个PageViewController,是这样的问题吗? – user2951346 2015-02-09 12:15:44
只写下你想隐藏的这三个函数。 – 2015-02-09 12:20:09
@ Pratik Patel:我的确如你所说,但它不起作用......我只是看到状态栏的风格改变 – user2951346 2015-02-09 12:26:28
我只是编辑您的问题,所以它更容易准确地了解你的要求。我希望我正确理解这个问题:)。 – 2015-02-09 12:05:35
试试这个:http://stackoverflow.com/questions/18979837/how-to-hide-ios-7-status-bar – anny 2015-02-09 12:16:07
@ Lea Cohen:非常感谢,我的英语不好。 :) – user2951346 2015-02-09 12:16:47