caldera.sac
caldera.sac

Reputation: 5108

How to hide status bar for specific viewcontroller in ios 9, using objective-C

I want to hide the status bar for specific view controllers, not for all. then I tried this,

[[UIApplication sharedApplication] setStatusBarHidden:YES]; in the `.AppDelegate.m` inside the `didfinishlaunchwithoption`  but it didn't work. and also it is deprecated.

then I tried in my viewcontroller

- (BOOL) prefersStatusBarHidden{
    return YES;
}

this also didn't work. anyone can help me with this.thnak you I don't want to use any deprecated methods here

Upvotes: 3

Views: 3041

Answers (5)

Aamir
Aamir

Reputation: 17007

Try the code below in your view controller.
Try the following method without deprication warnings:

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

}

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

Update for iOS 9
Add the following code in your viewController for hiding status bar.

- (BOOL) prefersStatusBarHidden {
    return YES;
}

Upvotes: 1

matt
matt

Reputation: 536009

I want to hide the status bar for specific view controllers, not for all.

Only the top-level view controller gets to say whether the status bar is hidden. Your prefersStatusBarHidden is not consulted because your view controller is not the top-level view controller — it has some kind of parent view controller which is in charge of the status bar.

Upvotes: 1

Pankaj Teckchandani
Pankaj Teckchandani

Reputation: 745

Add below code to your view controller..

 - (BOOL)prefersStatusBarHidden {

   return NO;
}

If you change the return value for this method, call the setNeedsStatusBarAppearanceUpdate method.

For childViewController, To specify that a child view controller should control preferred status bar hidden/unhidden state, implement the childViewControllerForStatusBarHidden method.

Upvotes: -1

MOHAMMAD ISHAQ
MOHAMMAD ISHAQ

Reputation: 998

Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to "YES" and set "UIViewControllerBasedStatusBarAppearance" to "YES". This will hide status bar for your app.

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

and call this method where you want,For example from viewDidLoad

[self prefersStatusBarHidden];

Upvotes: 1

Mahendra Kumar
Mahendra Kumar

Reputation: 59

Try below code in your view controller.

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

}

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

Upvotes: -1

Related Questions