Unable to hide statusbar in single UIViewControlle

2019-02-28 10:30发布

问题:

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];
}

回答1:

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

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;
  }


回答2:

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];


回答3:

try this one it's help for me-:

-(BOOL)prefersStatusBarHidden
{

  return YES;

}


回答4:

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; 
}