I am trying to hide/show the status bar in iOS 7 (and 6) programmatically, NOT ViewController based but method based.
For example if i press button 1 the status bar disappears, if i press button 2 the status bar appears.
I have tried all combinations here and from google, but all are viewcontroller based so far.
Does anybody have an idea how to do it, method based?
Use the UIApplication methods
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
on the instance [UIApplication sharedApplication]
Related
In some devices as iPhone 7 and 8 the navigation bar overlaps status bar after do navigating, the parent view controller has status bar hidden but I show and hide it in viewWillAppear and viewWillDisappear respectively. I tested in iOS 12 and it works.
I am using prefersStatusBarHidden to hidden the status bar.
Here the Image
Navbar Overlaps Status bar
Update:
Here an example project: https://github.com/FranklinSamboni/NavBarTestSwfit.
It work fine in iOS 12 but with iOS 13 the navigation bar overlaps status bar in iPhone 7,8
Images with iPhone 8 (simulator)
Home
The second view
Second View
Okay, I'm going to give one of those wishy-washy answers.
On the one hand, you've definitely found a new behavior in iOS 13. When you hide the status bar, the navigation bar shrinks. You could term this a bug in iOS 13...
On the other hand, it could be argued that what you are doing is wrong. If you have a navigation bar, you already cannot hide the status bar on a device without a bezel (iPhone X etc.), and now Apple seems to be assuming that if you have a navigation bar you won't hide the status bar at all. And that is a reasonable assumption, because it makes no sense to hide the status bar in portrait when there is a navigation bar, and especially in some children of the navigation controller but not others.
So you could file a bug report on this, but I don't think you'll get any joy from it. Apple is likely to reply that this is intended, or is at least a consequence of doing something they don't want to support. You have a navigation bar; allow the status bar to show.
I faced the same problem, after a few hours research, I found a not perfect but worked solution. Hope it will work for you.The code was written with Objective-C.
In viewDidAppear method of the secondViewController, hide statusBar first and show it at once.
Declare a member variable BOOL statusBarHidden in secondViewController
Implement prefersStatusBarHidden method from UIViewController
- (BOOL)prefersStatusBarHidden
{
return statusBarHidden;
}
Create a new method setStatusBarHidden
- (void)setStatusBarHidden:(BOOL)hidden
{
if (statusBarHidden != hidden)
{
statusBarHidden = hidden;
[self setNeedsStatusBarAppearanceUpdate];
}
}
Call setStatusBarHidden in viewDidAppear
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setStatusBarHidden:YES];
[self setStatusBarHidden:NO];
}
In some of app's view controllers status bar is hidden. But when user opens the app from a background, status bar becomes visible for a second, and then hides.
I tried:
to put [[UIApplication sharedApplication] setStatusBarHidden:YES]
into applicationWillEnterForeground: method. However, status bar becomes visible before this method is called.
check status bar's visibility when applicationWillResignActive:
self.isStatusBarHidden = [UIApplication sharedApplication].statusBarHidden ? YES : NO;, but it returns <nil>. (Then I wanted to hide status bar and show it when applicationWillEnterForeground - this leads to a completely opposite situation)
How to solve this problem?
P.S. View controller-based status bar appearance in my .plist file is equal to NO and Status bar is initially hidden is equal to NO too.
Are you keeping your settings like this?
You need to check status bar style Hide during application launch.
The problem is simple, the Profile viewController has a NavigationBar just under the status bar. I push another viewController on top of the current one. This new viewController hides the status bar.
When I go back USING A SWIPE BACK GESTURE to the Profile viewController, the navigationBar has moved up by the size of the status bar height.
The related question is UINavigationBar moving under status bar when another viewController hides status bar
Any ideas?
Actually,
in that case too, using the following also works.
[[UIApplication sharedApplication] setStatusBarHidden:NO];
Calling this in viewWillDisappear of the second view controller solves the issue.
The main View controller contains a main view and I add a tableView in within the view (the blue-ish color on the screenshot is the header of the tableview).
Somehow, this composition doesn't layout really well... I have no idea why.
Somebody wrote that to avoid this kind of layout issues, using a scrollView as a container makes the trick but I can't add tableViews to a scrollView...
If anybody has an explanation about why this layout problem happens, I'd be happy about it.
I am trying to remove the status bar from my app when moving between views in a UINavigationController.
I have a UINavigationController that has the status bar removed. I then select an image using UIImagePickerController, I think it is this that is resetting the status bar appearance.
After selecting the UIImage I push another view and present the image, the problem is that the status bar has reappeared.
I have tried a number of approaches including calling prefersstatusbarhidden on both views without without any luck.
Any ideas how to remove the status bar?
Thanks
If using iOS8, add
-(BOOL)prefersStatusBarHidden{
return YES;
}
to your view controller. You will need to add this to each view controller as required.
You could alternatively specify a value for the key View controller-based status bar appearance in info.plist to specify your status bar preferences app-wide.
Try hiding the status bar manually using this
[[UIApplication sharedApplication] setStatusBarHidden:YES];
I have an issue with my navigation bar.
The first screen of my app is a welcome screen, with two classic buttons in the center of the screen. No bars (tab or nav, and status is hidden with the setStatusBarHidden in the viewDidLoad). I only implemented one of the buttons but both will work the same way (the two screens are similar). So the first button loads up a "sign up" screen (a UITableViewController) with a form to fill in. There, the status bar is shown, and I added a navigation bar (in the attributes panel of my view controller), with a "send" button on the top right.
In the attributes panel of my "navigation item" (as it's called), I entered a name for the back button, which is correctly displayed (although I'd like to change the name, but I'll do it later).
My problem is that when I hit the back button, it takes me back to the "welcome" screen but the status bar is not hidden, there is a nav bar with no title and no buttons, and I can't find a way to hide them. I tried using viewDidLoad, viewDidAppear, viewDidUnload (in the sign up view) but nothing works (I can hide the status bar, but the view is loaded so there is a black space between the non-hidden nav bar and my content).
By the way, I have done most of the design using the storyboard, not with code, but I don't mind using both.
Can anybody help ? Thanks.
Hide the status bar and navigation bar in viewWillAppear: method and not in the viewDidLoad: method.If your dont want to show status bar or navigation bar,put that code in AppDelegate Class.
Edited:
This will hide your navigation bar in your View controller.Put it in viewWillAppear:
self.navigationController.navigationBarHidden = YES;
This hides your status bar.
[[UIApplication sharedApplication] setStatusBarHidden:YES animated: UIStatusBarAnimationNone];
Your view controller should have wantsFullScreenLayout set to YES, as well as hiding the status bar.Black space is showing your view is automatically didn't resized when you dont have status bar or navigation bar.you need to check auto-sizing in the storyboard "size inspector" in the right side pane tabs.
Edit 1:
This will hide your bars with animation:
[self.navigationController setNavigationBarHidden:YES animated:YES];
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];