Unable to hide statusbar in single UIViewControlle

2019-02-28 10:03发布

I want to hide staus bar in single view controller but my code is not working. I'm using the below code

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

&

-(void)viewWillApper:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}

4条回答
beautiful°
2楼-- · 2019-02-28 10:49

You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".

enter image description here

or

in

application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions write

 [[UIApplication sharedApplication] setStatusBarHidden:YES];

or

Add following line in viewdidload

[[UIApplication sharedApplication] setStatusBarHidden:YES
                                        withAnimation:UIStatusBarAnimationFade];

and add new method

 - (BOOL)prefersStatusBarHidden {
          return YES;
  }
查看更多
一纸荒年 Trace。
3楼-- · 2019-02-28 10:50

try this one it's help for me-:

-(BOOL)prefersStatusBarHidden
{

  return YES;

}
查看更多
你好瞎i
4楼-- · 2019-02-28 10:51

if you have View controller-based status bar appearance set to YES in app's plist, put this code in the view controller:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

and if View controller-based status bar appearance is set to NO, do the following whenever you want to hide the status bar.

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
查看更多
我命由我不由天
5楼-- · 2019-02-28 10:55

To hide status bar on a single VC:

1) Add this value to plist:

"View controller-based status bar appearance" and set it to "YES"

2) Add following to viewWillAppear:

[self prefersStatusBarHidden];

3) Add new method:

-(BOOL)prefersStatusBarHidden
{
    return YES; 
}
查看更多
登录 后发表回答