无法在单个 UIViewController 中隐藏状态栏

Unable to hide statusbar in single UIViewController

我想在单视图控制器中隐藏状态栏,但我的代码不起作用。 我正在使用下面的代码

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

&

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

您应该将此值添加到 plist:"View controller-based status bar appearance" 并将其设置为 "NO"。

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

 [[UIApplication sharedApplication] setStatusBarHidden:YES];

在 viewdidload 中添加以下行

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

并添加新方法

 - (BOOL)prefersStatusBarHidden {
          return YES;
  }

如果您在应用 plist 中将 View controller-based status bar appearance 设置为 YES,请将此代码放入视图控制器中:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

并且如果 View controller-based status bar appearance 设置为 NO,请在您想隐藏状态栏时执行以下操作。

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

试试这个对我有帮助-:

-(BOOL)prefersStatusBarHidden
{

  return YES;

}

要在单个 VC 上隐藏状态栏:

1) 将此值添加到 plist:

"View controller-based status bar appearance" 并设置为 "YES"

2) 将以下内容添加到 viewWillAppear:

[self prefersStatusBarHidden];

3) 添加新方法:

-(BOOL)prefersStatusBarHidden
{
    return YES; 
}