2

I've been trying to hide the status bar in SWRevealViewController,but hiding status bar shouldn't effect the other UIViewController, it should only hide it where Sliding-Menu opens only. to hide the text and the date etc.. !

I've tried the following :

    self.setNeedsStatusBarAppearanceUpdate()

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

But the status bar colour just changed to while colour and still unhidden ! I've no idea how is it possible to do ?

AaoIi
  • 8,288
  • 6
  • 45
  • 87
  • do you use storyboards? – Daij-Djan Aug 18 '15 at 12:33
  • for sure yes ,first the SWRevealViewController -> Empty UIViewController, which is connected to rear_view -> MenuController as UITableViewController. – AaoIi Aug 18 '15 at 12:35
  • If you want to hide the status bar in all controllers then you should see the link below it will help you. http://stackoverflow.com/questions/18979837/how-to-hide-ios-7-status-bar – jogshardik Aug 18 '15 at 13:09

3 Answers3

0

set the statusBarHidden property to be true before setNeedsStatusBarAppearanceUpdate() UIApplication.sharedApplication().statusBarHidden = true If you don't want the status bar hide in other views. You can show the status bar before your view disappear in viewWillDisappear

Roger
  • 973
  • 10
  • 15
  • This is gonna make a problem, because I'm having navigation controller on the UIViewController, and on the menu i don't have a navigation controller but only status bar. so when i navigate to the menu it also hides the status bar in the UIViewController which shouldn't happen. – AaoIi Aug 18 '15 at 12:18
  • @AaoIi Did you set the `statusBarHidden` to be `false` before navigation? Or you can try to do that in the view without navigationbar – Roger Aug 18 '15 at 12:31
  • @AaoIi Did the status bar show in the view without navigation bar before? – Roger Aug 18 '15 at 12:35
  • What happened exactly when i navigated to the SWRevealViewController, the status bar of the Old UIViewController hides without the Navigation Controller, and in the SWRevealViewController the status bar is hidden. and when i navigate back to the UIViewController the status bar comes back from top sliding .. – AaoIi Aug 18 '15 at 12:39
0

hide it when the menu is coming up:

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

for the code to work set this in your plist:

View controller-based status bar appearance to NO
(UIViewControllerBasedStatusBarAppearance)
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • This doesn't work too, we should play with childViewControllerForStatusBarHidden and childViewControllerForStatusBarStyle . but I've no idea how is it possible to do ! – AaoIi Aug 18 '15 at 12:26
  • edited - new way - tested and works. the revealer already implements `childViewControllerForStatusBarStyle` -- without that my 'old' way would have worked – Daij-Djan Aug 18 '15 at 12:49
  • It makes this issue again : What happened exactly when i navigated to the SWRevealViewController, the status bar of the Old UIViewController hides without the Navigation Controller, and in the SWRevealViewController the status bar is hidden. and when i navigate back to the UIViewController the status bar comes back from top sliding .. – AaoIi Aug 18 '15 at 12:54
  • yes sure.. it animates out and in and that looks bad :) but thats what you wanted – Daij-Djan Aug 18 '15 at 12:55
  • I answered the question.. if it were me I wouldn't do it :D – Daij-Djan Aug 18 '15 at 12:55
  • my question is hiding the status bar of the menu without effecting the other UIViewControllers status bar too :) – AaoIi Aug 18 '15 at 12:56
  • then I didn't get that :) – Daij-Djan Aug 18 '15 at 12:58
  • You may check the gmail app on App Store and see what i mean when you open the menu and the status bar. you'll get what i mean ! – AaoIi Aug 18 '15 at 12:59
  • please note I haven't/won't download the gmail app just for this ;) – Daij-Djan Aug 18 '15 at 13:18
  • oh Yeah ! I'm just trying and testing, :D – AaoIi Aug 18 '15 at 13:45
  • I've tried it but it still showing, have a look here : [the image here](http://i921.photobucket.com/albums/ad53/Johann_1990/Screen%20Shot%202015-08-23%20at%2012.25.30%20PM.png) – AaoIi Aug 23 '15 at 09:30
  • @AaoIi I am having the same problem. Did you figured out problem and found the solution? Thanks – virusss8 Mar 27 '17 at 14:24
  • 1
    @virusss8 check my answer here : http://stackoverflow.com/a/38636410/3989689 , you only need to place it in viewWilAppear and viewDidDisappear of your side menu vc. – AaoIi Mar 27 '17 at 21:30
  • 1
    @AaoIi I founded another one. Somehow constraints in menuTableView was broken, and with snapKit, I just set constraints to 0 to self.view. ;) – virusss8 Mar 28 '17 at 09:20
0

I put this in LeftMenuViewController and HomeViewController.

-(BOOL)prefersStatusBarHidden{
  return YES;
}

for example, I put the following in AppDelegate.m. And LeftMenuViewController means viewController for "the left menu".

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