Storyboard / Navigation Bar issue in Xcode - ios

I'm experiencing a bit of a weird issue and I'm hoping someone can point me in the right direction.
In Xcode, using storyboard, I have a view controller that inherits a navigation bar. This is working fine. Where the issue is is that when I add an element to the view controller (ie, UIButton, UILabel, etc) and run the application on my phone, the Y positioning of the element is off by the amount of the height of the navigation bar.
Let's say I wanted to have a UIButton DIRECTLY BELOW the navigation bar, I would have to move it UNDER the navigation bar, to the very top of the view controller on the Storyboard. On my phone it would be directly below (Y positioning) the Navigation Bar.
I'm fairly new to iOS development, so I'm not even sure where to begin. I tried enabling / disabling Auto Layout, which didn't change anything.

Try this:
Click on your view controller, in the Attributes Inspector uncheck the "Adjust scroll view insets" option.

Related

Implementing Safe Areas for Tab Bar Controller and iPhone X

What I'm trying to do: place the tab bar at the bottom of the iPhone X display where it belongs, and also put the navigation bar at the top of the display.
I've been trying to accomplish what I thought would be a straightforward task of using Safe Areas in the storyboard to position the tab bar near the bottom of the iPhone X's display. I'm missing something fundamental.
I've read a lot of writeup about how to do this, including this one. It includes a screenshot of a tab bar control scene that looks like this:
But I can't create a view inside my Tab Bar Controller to put my tab bar item in, as the article mentions. It's my understanding that I'll use the safe area of the view that should contain the tab bar item. But it won't let me put a view anywhere except outside the Controller view. I've tried using "embed" - but all options are greyed out.
Same goes for a navigation controller to move a navigation bar to the top of the display.
The funny thing is that IB renders it in the right place, but on my device, the tab bar is way above where it should be (and the navigation bar way below).
I have "Opens in" set to "Latest Xcode (9.0) and Builds for iOS 11.1 set in the scene's "Interface Builder Document", and "use Safe Area Layout Guides" is checked. I'm not using any custom classes for my tab bar controller or tab bar. I'm using XCode 9.3 and iOS 11.3.1
What's the simple thing that I'm missing? Thanks in advance.
The article explains how to adapt your app if you're using a custom navigation bar or a custom tab bar.
If you're using the standard navigation bar or tab bar then you have to make sure it's top or bottom (depending on the element) constraints are connected to the superview and not the Safe Area layout guide. UIKit makes sure these elements are correctly rendered with spacing at the top or bottom on an iPhone X device. Check out this screenshot for clarification.

Navigation bar item automatically changes its height and position in storyboard

I have a project which was build in Xcode 8.2 and now when I run it using Xcode 9.2. I am facing problems with the custom navigation title and bar buttons in the view controllers. In my storyboard I have a View Controller and on its Navigation bar I have a custom navigation view with a label used as the navigation title.
Since we cannot add constraints on the navigation view, I have given autolayout for both the view and label. Now when I run the project, the custom navigation title has disappeared. So I opened the storyboard to check what really happened, I was shocked to see that navigation view's origin.y value is changed to some other value, like -44, -88, etc. Now I edited the origin.y value, saved and run the project, but still the view was not seen. So now when I checked back in the storyboard the frame of the view was changed to some other value. I tried creating new custom navigation view, but no luck. This keeps happening and I am really worried. I really appreciate if you guys can give me some information on this issue.
Click to show screenshot of custom view in the navigation bar

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

scroll up tableview to hide half of navigation bar and the whole table gets offset

I'm using a UITableViewController embedded in a navigation controller, I've checked the "hide bars on swipe" for the navigation controller in the storyboard. No crazy code, scrollview functions are not overridden, didn't write any code that would offset any views.
When I scroll up the tableview a tiny bit and release it when the navigation bar is half hidden, the whole table gets offset and it's off screen (sometimes the top left corner of the table is visible), then if I scroll up the table view a bit, it's back to its normal position, if I check "adjust scroll view insets" in the storyboard, the whole screen flashes black.
Has anyone encountered the same problem?
p.s. I'm using Xcode 9 beta with iOS 10.3, not sure if this has anything to do with it.
EDIT:
Scroll navigation bar half way
The view after releasing
So I created a new set of TableviewController and NavigationController, and tested it step by step by adding changes to it, it turned out that I had set my navigation bar to be translucent in the storyboard, once I unchecked it the issue was resolved. There's still an unwanted bounce effect if I release the navigation bar at half hidden position, which appears to be the view adjusting the offset, but it's way better than what it was like.
P.S. make sure "Adjust scroll view insets" is checked.
EDIT:
Turns out setting extendedLayoutIncludesOpaqueBars to True also resolves this issue, if you want to keep the navigation bar opaque.

Navigation Bar is too small

I am working on an iPad app and when I try to put the navigation bar on the first view controller, it fits in the main storyboard but is too small (also comes in contact with the status bar) when I run the simulator (as seen in the picture below):
The width and height in the storyboard are set to regular, not sure if it is relevant to this question. How do I fix this?
It looks like you're just adding a navigation bar. Are you sure you don't want a navigation controller?
If you do just want the navigation bar the you need to add constraints to pin it to the left and right of the screen.
Click the "add constraints" button and pin to left right and top.
Click on your view and go to Editor > Embed in > Navigation Controller.

Resources