隐藏SWRevealViewController中的状态栏

时间:2015-08-18 12:01:13

标签: ios swift swrevealviewcontroller

我一直在尝试隐藏SWRevealViewController中的状态栏,但隐藏状态栏不应影响其他UIViewController,它应该只隐藏Sliding-Menu打开的位置。隐藏文本和日期等。!

我尝试了以下内容:

    self.setNeedsStatusBarAppearanceUpdate()

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
}

但状态栏的颜色只是改变为颜色而仍未被隐藏! 我不知道怎么可能这样做?

3 个答案:

答案 0 :(得分:0)

statusBarHidden之前将true属性设置为setNeedsStatusBarAppearanceUpdate() UIApplication.sharedApplication().statusBarHidden = true 如果您不希望状态栏隐藏在其他视图中。您可以在视图消失之前显示状态栏viewWillDisappear

答案 1 :(得分:0)

菜单出现时隐藏它:

//delegate method
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position {
    BOOL rm = position != FrontViewPositionLeft;
    [[UIApplication sharedApplication] setStatusBarHidden:rm withAnimation:UIStatusBarAnimationNone];
    [self setNeedsStatusBarAppearanceUpdate];
}

要使用的代码在plist中设置它:

View controller-based status bar appearance to NO
(UIViewControllerBasedStatusBarAppearance)

答案 2 :(得分:0)

我把它放在LeftMenuViewController和HomeViewController中。

-(BOOL)prefersStatusBarHidden{
  return YES;
}

例如,我在AppDelegate.m中添加了以下内容。 而LeftMenuViewController意味着viewController用于"左侧菜单"。

HomeViewController *home = [[HomeViewController alloc]init];
LeftMenuViewController *leftMenu = [[LeftMenuViewController alloc]init];

UINavigationController *mainNC =
[[UINavigationController alloc]initWithRootViewController:home];

UINavigationController *menuNC =
[[UINavigationController alloc]initWithRootViewController:leftMenu];

_revealVC = [[SWRevealViewController alloc]initWithRearViewController:menuNC
                                                  frontViewController:mainNC];
self.window.rootViewController = _revealVC;
[self.window makeKeyAndVisible];