Hide status bar without automatically adjusting a navigation bar's frame - ios

When hiding the status bar in a UINavigationController-based app by using:
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .None)
the UINavigationBar's frame is adjusted. This is because the status bar is a UIView itself and the top of the navigation bar is constrained to the bottom of the status bar. So when the status bar is moved offscreen, the navigation bar moves up with it.
I've tried a number of ways to prevent this behavior. I've tried manually assigning a frame to the navigation bar to no avail. I've tried subclassing UINavigationBar and overriding sizeThatFits() while checking if the status bar is hidden or not and assigning a frame that way. Nothing. I've read other SO posts but no one seems to have a working solution. Help?

Related

iOS, How to layout views without scrollview under the status bar and a navigation bar

I'm new to iOS,
One simple case of my trouble is:
How to place a UILabel (or any UIViews) JUST BELOW a navigation bar and the status bar? The layout is expected to be dynamic(Say these views always stay closely below the nav bar, no matter how the nav bar or the status bar's heights change), like this:
Some situations have already been considered:
I know that a scrollview is able to layout automatically by using automaticallyAdjustsScrollViewInsets in UIViewController. The case here is not allowed using scrollview though.
The status bar's height can be a constant value of "20" in most iOS device, and the default navigation bar's height can be "44" by the same way. The difference is that I can dynamically get the status bar's height anywhere in the code by using [[UIApplication sharedApplication] statusBarFrame, although the navigation bar's height can be referred by the same "get frame" way, my most cases are to get the height BEFORE the navigation bar gets added into super view, so I always get 0 height from its frame.
Although in most cases the total height of the status bar and the navigation bar can be defined as a value of "64", it is not a eternal way for the future consideration because of more new devices may change this value.

How to set the status bar to look like the system message app in iOS?

First, look at the picture below.
The middle is the message app, the left and right are my apps.
As you can see, in the message app, the status bar and top bar are both grey.
In the left one, the top bar is not translucent. The status bar and the top bar are all white.
In the right one, the top bar is translucent, which is the default style. The top bar is grey, but the status bar is white.
My question is, how to set the status bar to grey? As I can see in the target info part, the status bar style is already 'grey style(default). But it runs in white in my iPhone 5 iOS 7.1.1.
It turns out that #Panayot Panayotov is right. In Navigation controller, everything is fine.
I have compared the Navigation controller and Navigation bar alone. It turns out that in Navigation controller, the Navigation bar's x, y, width and height is 0, 0, 0, 0, which means it is right behind the status bar and also with a autolayout size. Since the status bar is translucent in iOS7, the color of the status bar and navigation bar are the same.
If you use Navigation bar alone, it has a fixed height 44, which can not be changed. That height can't cover the status bar and navigation bar items together. So they colors are different.
Finally the answer is to use navigation controller, not using navigation bar alone.

How do you make the status bar appear iOS

This is getting very frustrating for me because I can't get the status bar to appear in my app. Everything related as far as UI is done on storyboard. when i set my status bar:inferred, top bar: inferred in my navigation controller, the status bar shows up fine. However, I do not want the top bar to appear as it interferes with my layout, so I set the top bar to none, which results in no top bar or status bar.
How can I just make the status visible without affecting my layout? (auto-layout is enabled)
So I did more googling and research, turns out I just had to add View controller-based status bar appearance as the key and the value as NO in the .plist file

ios move ui view down after hiding status bar

I've read a few questions here and searched around a bit but nothing seems to solve my problem. I have a side navigation controller of which I am sliding the status bar (using a technique outlined here: Moving status bar in iOS 7).
In any event, when I hide the status bar to begin the slide (as soon as I tell the view to hide the status bar and add a fake one), the entire view moves up behind my faux status bar. Is there any way to move the view down so that the faux status bar appears directly above the view?
may be some autolayout issueAs there is no status bar , the view frame went to frame.origin.y=0. Try setting the frame to origin.y=20 before you hide the status bar.
If you are adding fake status bar as subview to mainView. set frame of fake status bar view to (origin.y=-20)

iOS 7 - Status bar overlaps the view content

I am using status bar in my app and wanted to maintain the compatibility between ios 6 and ios 7. I wanted status bar to behave same as ios 6. I don't want status bar to overlap view controllers.
Try adding the following code in your view's viewWillAppear function:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// if this is ios7 this code will make the view appear properly below the navigation bar
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
}
}
Try this~
if(OVER_IOS7){
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController.navigationBar setTranslucent:NO]
}
Try this.
add this key into info.plist file
View controller-based status bar appearance
set value for this to:- No
In iOS 7, the status bar is transparent, and other bars—that is, navigation bars, tab bars, toolbars, search bars, and scope bars—are translucent. As a general rule, you want to make sure that content fills the area behind the bars in your app.
Most bars also draw a blur behind them, unless you provide a custom background image for the bar.
iOS 7 introduces the barPosition property for identifying bar position, which helps you specify when a custom background image should extend behind the status bar. The UIBarPositionTopAttached value means that a bar is at the top of the screen and its background extends upward into the status bar area. In contrast, the UIBarPositionTop value means that a bar is at the top of its local context—for example, at the top of a popover—and that it doesn’t provide a background for the status bar.
By default, all bar buttons are borderless. For details, see Bar Buttons.
The Status Bar
Because the status bar is transparent, the view behind it shows through. The style of the status bar refers to the appearance of its content, which includes items such as time, battery charge, and Wi-Fi signal. Use a UIStatusBarStyle constant to specify whether the status bar content should be dark (UIStatusBarStyleDefault) or light (UIStatusBarStyleLightContent):
UIStatusBarStyleDefault displays dark content. Use when light content is behind the status bar. image: ../Art/status_bar_default_iphone_2x.pngimage: ../Art/status_bar_default_ipad_2x.png
UIStatusBarStyleLightContent displays light content. Use when dark content is behind the status bar. image: ../Art/status_bar_light_iphone_2x.pngimage: ../Art/status_bar_light_ipad_2x.png
In some cases, the background image for a navigation bar or a search bar can extend up behind the status bar (for details, see Navigation Bar and Search Bar and Scope Bar). If there are no bars below the status bar, the content view should use the full height of the screen. To learn how to ensure that a view controller lays out its views properly, see Using View Controllers.
In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. If you prefer to opt out of this behavior and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO.

Resources