Navigation controller view offsetting on status bar hide on iOS 7 - ios

Weird iOS 7 issue I am having.
I have a UINavigationController added as a child view controller to my main view controller.
When I hide the status bar (by setting preferredStatusBarHidden and calling setNeedsStatusBarAppearanceUpdate), the navigation controllers top view controller recesses the 20 pixels that the status bar did, but not the UINavigationBar. This is only happening on iOS 7 - and I cannotfind a work around. If I rotate the device, it corrects the issue?
Before I hide the status bar
After I hide the status bar
I have tried calling layoutIfNeeded and updateViewConstraints. These did nothing. Was able to do conditional checks for version number and add constraints to fix, but this breaks things worse on rotate and I would prefer a cleaner solution if anyone has any ideas.
Thanks.

Related

Increasing UINavigationController navigation bar height in Landscape mode

I have seen too many posts on this but unable to find satisfactory answer to this question. Specifically, I want to increase the height of navigation bar of UINavigationController by around 20 pts when iPhone is in landscape mode (not otherwise), and also set a custom image for it's Background. What I have found so far:
Manipulating frame of UINavigationBar managed by navigation controller,
Hacks such as sizeThatFits along with subclassing UINavigationController -- doesn't work for me in iOS 12 and also it is a kind of hack,
Hide the default navigation bar in UINavigationController and instead replace it with a custom navigation bar. But I don't see any sample code. Any sample code will be appreciated.
Edit: Here is how I want my custom navigation bar to look like that works across UINavigation hierarchy.

iPhone X - Hidden status bar pushes Navigation Bar upwards

I'm testing iPhone X behavior using the Xcode simulator. For some odd reason, if I'm hiding the Status Bar the Navigation Bar pushed upwards causing the title to completely disappear and cutting the left and right buttons. This is happening only on the iPhone X.
Illustration:
How can I hide the status bar and keep the Navigation Bar at a visible position?
UPDATE:
Sample project for your convince:
https://drive.google.com/file/d/0B5qJARV-Oc9ra1hvZkpXZm9lRUE/view?usp=sharing
One solution is to embed the navigation controller inside a container view controller which is properly constrained to the safe area.
Just create another view controller and drag a "Container View" from the Object Library. This view has top, bottom, leading, and trailing constraints to the safe area, all with constants equal to 0. If you control-drag from the container view to the navigation controller, you'll get an option to set an "embed segue" which will embed the selected view controller as a child view controller.
I set the status bar to be hidden on the new view controller I created, and it works fine.
This feels like something that UINavigationBar should handle automatically, but this workaround seems like it should work pretty well.
Another note: if you change the color of the navigation bar, you'll also need to create another view above the container view, and change its color to match the color of the navigation bar.
I, for a small app, changed from using a Push to a Modal segue and adding in my own navigation bar. I used Push because it looks good, and already had a Modal for another part, which I wanted to animate differently for style reasons.
For smaller apps this may be the quickest and easiest solution, but my next update I need to use the navigation controller. For that I think I'll switch on the status bar, which is no big deal for me and allows it to work.
I think you need to use "safeAreaLayoutGuide" new update in iOS 11
Apple has provided us with the necessary APIs to get around the unsafe regions of this iphone x. We do this by using the new safeAreaLayoutGuide anchors in our code
safeAreaLayoutGuide

iOS 11: Pop view controller with scrollView inside navigation controller with opaque navbar result in weird content animation during transition

Pop view controller with scrollView inside navigation controller with opaque navbar result in weird content animation during transition
The content will be somewhere below its original position during transition, and interactive pop will make this very obvious.
Enabling Safe area does not fix this.
It is a bug in iOS 11 I believe.
Here's a rdar about it:
http://openradar.appspot.com/34465226
You can walk around this issue by check the Extend Edges: Under Opaque Bars box in storyboard or set [self setExtendedLayoutIncludesOpaqueBars:YES] manually in code.

Update positionForBar for toolbar

In my app I use a toolbar on the top because it lays out bar button items better for what I need, and I set the toolbars delegate to the view controller and tell it to be top attached. I also have a setting that will hide the status bar, so the issue that is happening is that when the status bar is set to hidden, and the app is closed and then re-opened, positionForBar is called but since there is no status bar, it doesn't do anything to the toolbar, so when I turn the status bar back on the app looks strange, and the toolbar is 20px down, and the status bar is showing but there is no background to the status bar, so it looks strange. positionForBar is being called still though but for some reason I need to close the app again before the toolbar will draw behind the status bar again. I have found out that if I remove the toolbar from the superview and re-add it again, it will draw behind the status bar, or i can remove positionForBar and have my own view be the background for the status bar, my old issue with this solution is that it won't be transparent (I could maybe put a 20px toolbar there though maybe?) and my problem with removing it and re-adding the view is then I will need to move a ton of my code around because remove it and re-adding it messes with constraints so I will need to fully reconstruct the entire view just for it to redraw behind the status bar. Is there a way to just refresh the view or something? I have tried setNeedsLayout and setNeedsDisplay and nothing really works for it to redraw besides removing and re-adding
Try manually setting the UIToolbar's frame:
topToolbar.frame = CGRectZero
Or updating the constraints, either will cause the UIToolbar to update its attachment.

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)

Resources