Cbas
Cbas

Reputation: 6213

Can't hide status bar on launch

I'm building an iOS 9 app with horizontal pages navigation and need to show the status bar on some pages, and hide it on others. I want to use the fade in/out animation so I have to set

View controller-based status bar appearance = NO

and update the status bar like this:

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

This procedure works perfectly when navigating between pages, but I can't get rid of the status bar on launch.

I have tried setting: Status bar is initially hidden = YES

Adding this to the NavigationControllers viewDidLoad:

[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];

Adding this to AppDelegates didFinishLaunchingWithOptions:

application.statusBarHidden = YES;

Adding this to the ViewController of the initial page:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

Checking the "Hide status bar" option in General->Deployment Info

And setting "Status Bar" to "None" in the linked storyboard element

But the status bar is still showing up on launch. How can I get rid of the status bar on launch without changing the value of View controller-based status bar appearance ?

Upvotes: 5

Views: 2789

Answers (5)

nikhil84
nikhil84

Reputation: 3207

Just tick the hide status bar in project setting as below.

  1. Project setting - For hiding the status bar at launch of app.

Hide Status bar

  1. Add below in viewController for which you need to hide.

- (BOOL)prefersStatusBarHidden { return YES; }

/------ UPDATE -----/

  1. With tick of hide status bar Without status bar

  2. Without tick of hide status bar With status bar

/------ Animate Status Bar -----/

In plist.

View controller-based status bar appearance = NO

Then in viewWillAppear method.

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

Upvotes: 4

Cbas
Cbas

Reputation: 6213

Turns out what I was doing was correct, but there was an errant [[UIApplication sharedApplication] setStatusBarHidden:NO]; buried in inherited code. I grepped it, but overlooked that line...

(use git grep StatusBar to find lines of code in a git repo that mutate the status bar)

Also, the only code needed is:

View controller-based status bar appearance = NO (in plist)

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

anywhere the status bar needs updating (usually in viewWillAppear)

Upvotes: 0

Pradeep Tokalwad
Pradeep Tokalwad

Reputation: 80

Goto Targets->General->Deployment Info: and under that select Hide Status Bar option.

Upvotes: 0

Manuel Escrig
Manuel Escrig

Reputation: 2835

In order to achieve what you are looking for you need set in the app.plistfile:

Status bar is initially hidden to YES

View controller-based status bar appearance to NO

Then in every view controller to show it

[[UIApplication sharedApplication] setStatusBarHidden:NO];

or to hide it:

[[UIApplication sharedApplication] setStatusBarHidden:YES];

Upvotes: -1

Nikunj5294
Nikunj5294

Reputation: 391

changing plist file : 

set Status bar is initially hidden = YES

add row: View controller-based status bar appearance = NO

enter image description here

Upvotes: 1

Related Questions