Unable to remove top bar for iOS 10 - ios

I have tried almost all the answers but I can't get it to work.
What I have tried so far.
Target/Generar/Deployment Info: Status Bar Style -> Light, Hide status bar checked.
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
- (BOOL)prefersStatusBarHidden {
return YES;
}
and
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
What else can I try?

The problem is that the view controller in which you are saying this:
- (BOOL)prefersStatusBarHidden {
return YES;
}
...is not the view controller that is consulted with regard to the status bar's visibility. That view controller is the top-level view controller: the ultimate root view controller. Your view controller is just a child of that view controller, so your prefersStatusBarHidden is never called.

Related

Hide ios status bar when "View controller-based status bar appearance"=YES

I need to change status bar style depending on the view controller so in my plist-file "View controller-based status bar appearance" is set to YES.
And I need to sometimes hide the status bar!
I'm trying to use setStatusBarHidden but it seems to work only if "View controller-based status bar appearance" is set to NO ...
So is there a way to hide the status bar ?
First, declare a variable to indicate hidden or not:
#interface ExampleViewController
{
BOOL statusBarHidden;
}
Second, override UIViewController's method which depends the variable:
- (BOOL)prefersStatusBarHidden {
return statusBarHidden;
}
Finally, when you need to hide status bar, do:
statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];
When you need to display status bar again, do:
statusBarHidden = NO;
[self setNeedsStatusBarAppearanceUpdate];

UIStatusBar will not go away. Sadness and frustration ensues

Tried everything. Just trying to hide it for one view controller.
.plist:
Status bar is initially hidden = NO
View controller-based status bar appearance = YES
view controller:
- (BOOL)prefersStatusBarHidden {
return YES;
}
//I shouldn't have to do this, the above method should suffice. Doesn't work anyway
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Nothing works. Status bar is still there, staring me in the face, laughing through it's ugliness. What do I need to do???
EDIT: prefersStatusBarHidden does not even get called. This view controller is pushed onto the navigation stack via push segue.
In any custom containing view controller, implement childViewControllerForStatusBarHidden, returning the current child view controller that should controller the status bar appearance (in this case, the navigation controller).
This will let the system follow the view controller hierarchy down to the current "top" view controller, and it's that view controller's prefersStatusBarHidden which will be queried.
In your custom containing view controller, if the current "active" child view controller changes, call setNeedsStatusBarAppearanceUpdate to let the system know.
The key here was that this was never getting called in the view controller:
- (BOOL)prefersStatusBarHidden {
return YES;
}
Tracing backward, it was not called in the parent navigation controller either. This is because the nav controller was owned by a root view controller. The root view controller did call this method, but did not pass it on to the nav controller, and thus not to any other child view controllers. So for anyone having the same issue and trying to debug, try to track down the view controller at the "root" of your hierarchy.
So in my case, I post a notification from any view controller (viewWillAppear) that I want to hide the status bar. This notification is then consumed by the root controller:
- (void)hideStatusBar:(NSNotification *)notification {
self.hideStatusBar = YES;
[self setNeedsStatusBarAppearanceUpdate];
}
Which forces this method to be called on the root controller:
- (BOOL)prefersStatusBarHidden {
return self.hideStatusBar;
}
And everything works as expected. The same can be done for showing the status bar again.

Status Bar iOS7

I have two views and I need one to be able to show a white status bar and the other to show no status bar. I have successfully made it show NO status bar but have not been able to have the Main view have a White status bar. I have to use View controller-based status bar appearance = YES because otherwise When i go back from the "no status bar view" it makes it makes the whole app have no status bar. Why won't the status bar be white!?!
Current Code for dismising status bar:
-(BOOL)prefersStatusBarHidden
{
return YES;
}
-(void)ViewDidLoad {
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
Current Code for trying to make the status bar white:
- (void)viewDidLoad {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
[self setNeedsStatusBarAppearanceUpdate];
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
You shouldn't be calling prefersStatusBarHidden in your first block, you should be implementing it to return true.
Make sure you have View controller based status bar appearance (UIViewControllerBasedStatusBarAppearance) set to yes in your Info.plist file.
What this all means is that in the VC where you want the status bar hidden you need to put:
-(BOOL)prefersStatusBarHidden
{
return true;
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
In the other VC, put:
-(BOOL)prefersStatusBarHidden
{
return false;
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Just checked it out and it all seems to work as expected. Note that in iOS 7, UIStatusBarStyle only controls the color of the text in the status bar, the background color is determined by the navigation bar itself.
Why won't the status bar be white!?!
Well, simply because it is transparent. The "background colour" of the status bar is now (post ios7) the colour of the view/window behind the status bar.
but have not been able to have the Main view have a White status bar
The solution I commonly use, is to force the navigationController's navigationBar to render below the status bar rather than behind it. This way, the navigationBar's colour/background image doesn't extend under the status bar and the status bar's "background colour" is now the colour of the window.
To force the navigation bar to start below the status bar, you set its clipsToBounds property to YES.
_navigationController.navigationBar.clipsToBounds = YES;
To set the background colour of the window,
self.window.backgroundColor = [UIColor whiteColor];
Ref: Ironically, our "solution" was someone else's "bug" :)

Status bar in single view hide/ style

in my app I've multiple views . I need to hide the status bar for one view ( this vC2 is in order navigationC -> VC ->push to vC2) . it works firstly by setting
View controller-based status bar appearance = NO in plist
and then use
[UIApplication sharedApplication].statusBarHidden = YES; in the viewWillAppear
and [UIApplication sharedApplication].statusBarHidden = NO; in viewWillDisappear
to reback the status bar.
Then , I want to set the status bar with light colour style for another single view (VC3) in the same app. only one way works with me is
by setting View controller-based status bar appearance = YES and use
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
in the VC3.m
my problem is around View controller-based status bar appearance which used with NO value for hiding status bar and used with YES value for light style of status bar
Can I combine the the hiding / and style status bar in my app?
My target is iOS7
YOu can by using this function in viewController:
- (BOOL)prefersStatusBarHidden {
return YES;
}
The plist boolean has to be YES and you can add something more:
Try
[self setNeedsStatusBarAppearanceUpdate]
And in case you have view controllers as childs of other viewControllers, the last child is the one that should decide
If the VC is child of another VC (this on the first level VC that you subclass, not need if you are using a navigation without subclassing)
- (UIViewController *)childViewControllerForStatusBarHidden {
return _myChildViewController;
}

How to hide status bar in iOS 7?

I have tried setting the following in my app .plist file:
View controller-based status bar appearance: NO
And while this removes it from my initial view controller, once I go to another view and come back with my navigation controller, it comes right back and this time it does not disappear. Also, I don't see why it would matter but I have also set the status bar under simulated metrics to "None" but that doesn't seem to help. I know i am going to have the navigation bar but the status bar I need gone.
How can I get this done? Please provide a detailed answer, sample code would be great!
Update: This is NOT a duplicate solution as I have tried all other solutions and NONE seem to work for me. Most recently I tried
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Again, with no results. When the app initially launches a status bar is NOT present, after the user visits another view, the status bar is now present in the 2 and other views and does not go away. Even if you go back to the main view.
I have tried all of the suggestions that were posted here, unfortunately what happened here was a small mistake, in my viewDidLoad I had:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
But in my viewWillAppear I had:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
So this was just an issue of overriding, problem fixed now.
To hide status bar:
if [View controller-based status bar appearance: NO]: in AppDelegate.m call
[[UIApplication sharedApplication]setStatusBarHidden:YES];
else: in every view controller
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Try this 2 steps:
In .Plist file of project set the property:
View controller-based status bar appearance = NO;
and
2.In all view controller's .m file in viewDidLoad method put this line of code:
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Use this method in the View Controller which you'd like the Status Bar hidden:
- (BOOL)prefersStatusBarHidden {
return YES;
}
This should work :
// In iOS7 this gets called and hides the status bar so the view does not go under the top iPhone
// status bar
- (BOOL)prefersStatusBarHidden {
return YES;
}
none of these work for me.
when i try this method i get the message "use of undeclared identifier preferstatusbarHidden
include - (BOOL)prefersStatusBarHidden {
return YES;
}
I don't know what to do anymore. I tried setStatusBarHidden, prefersHiddenStatusBar and still no results. Finally i have went through the below you tube link :
https://www.youtube.com/watch?v=FtpBXdMSqRQ
It worked for me.

Resources