Hide Bottom Bar When Pushed through Autolayout - ios

I have a UITabBarController with one UINavigationController holding a UIViewController as root view controller.
when tapping one of the button in the UIViewController, I push a regular chat window UIViewController (with TableView + Input View) end hiding the bottom tab bar. (using the "Hide bottom bar when pushed" flag)
In storyboard I added a regular UIView subclass to VC that look like a bottom bar, and I use Auto Layout to pin it to the bottom of the VC view.
The problem
when I push VC it takes a second for this view to pin to the bottom, it looks like auto layout pin it to the bottom as if the tab bar is not hidden and after a sec it recognise that the tab bar is hidden and moves it to the real bottom of the view.
For clear info check this screen shot
Now I will let you the know the constraints of the table view..
Now I am showing the constraints of the InputView
I am also adding my View hierarchy...

I had a similar issue in my project. I solved it by selecting the view I wanted anchored to the bottom (in your case, the input view), held Command, and selected its superview (both views should be highlighted now).
Then I selected the align button at the bottom of IB:
And added a Bottom Edges constraint.
What I had done initially is used the pin menu to pin the view to its superview, but it appears that will pin it to the bottom layout by default, which causes that weird movement during the transition.
EDIT:
After seeing the latest screenshot, the problem could lie in one of the superviews. I'm assuming that chatWindow is a UIView, and your Scroll View is horizontal only. Here's what your should check:
chatWindow is pinned to the scrollView's bottom similar to what I've outlined above.
scrollView is pinned to its superview as I've outlined above.
Moving the inputView outside of the scrollView to the root superview. Then one by one move it down the hierarchy towards its current location.

Related

How can I add a contraint to the root view instead of TopLayoutGuide?

My ViewController is embedded in a UINavigationController, and it has a view that should be aligned with the top of root view. The root view has dark gray background, and occupies full screen. But this is what it looks like now:
As you can see, the root view is displayed below the status bar, which is expected. But the subview (black) is displayed below a white strip. I guess this is the top layout guide, and my subview has a constraint with its top equal to the bottom of the top layout guide. After I remove this constraint, I cannot add a constraint from my subview to the root view by Ctrl-dragging, Xcode always set up the constraint with top layout guide.
My question is:
How can I add a constraint top of subview == top of root view?
Why does the top layout guide occupy the white region?
self.automaticallyAdjustsScrollViewInsets = true
The default value of this property is true, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to false if your view controller implementation manages its own scroll view inset adjustments.
You can also set this property from Interface Builder

Gap between top of UIScrollView and adjoining view

I'm trying to figure out why there's a gap between my scroll view (topped by the pink) and the upper view (black).
I have created this in interface builder. The pink view is inside a UIScrollView that is set to have its top == bottom of the black view above it:
Why is there this gap and how can I stop it?
Here is a slice of the entire screen to give you an idea:
I am having the same difficulty both at the top and bottom of the scroll view. There is a white gap between the top view of the scroll view and the next view up, and similarly there is a gap at the bottom view for the scroll view and the bottom of the screen. I tried turning off 'bounces enabled' but that has not fixed the problem. What gives?

view shifts down after being presented on screen when hiding tabBar in a navigationController stack in iOS

I am trying to hide my tabBar when pushing to a new viewController. I achieve this by ticking Hide Bottom Bar on Push in storyboard. The problem is that the new view that is being pushed to momentarily shows it's original position (as if the tabBar was still there) before shifting downwards to the correct position.
After searching for some time I found a similar post:
Auto Layout and "Hide bottom bar when pushed"
Unfortunately the solution of selecting the bottom constraint of the new view to Bottom Layout Guide.Bottom is no longer available in iOS 9 (it is greyed out). I followed several suggestions to set the bottom constraint to the container margin but it did not help this shift downwards.
Has anyone found a solution for this problem? It seems the geometry of hiding the tabBarController is only recognised after the push transition has completed.
It turns out my inputAccessoryView was causing the odd scrolling behaviour. The solution that worked for me was to add view.layoutIfNeeded() just before returning the accessoryView in the override:
override var inputAccessoryView: UIView? {
get {
view.layoutIfNeeded()
return accessoryView
}
So for this special case that involves a navigationController embedded in a tabBarController where you like to push to a viewController that hides the tabBar:
check Hide Bottom Bar on Push on storyboard
pin the bottom of the view you are presenting to the container bottom (use method suggested above or just select the pin icon at the bottom of your screen and on the bottom constraint select the drop down arrow and pin to view)
Then finally if you are using an inputAccessoryView, add layoutIfNeeded() in the override to the getter as I have done above.
In Xcode7 you have to right click your element, draw a line to the bottom until the constraint selector pops up. Constraint selector
Then press ALT and now you'll get the desired Bottom constraint

UIView Under Nav and Tab Bars

Using storyboard and Swift, I have a view controller which has two elements on it. A UITextField, and a UIView, which I use merely to give a colored border to the UITextField. The UITextField is a child of the UIView. See:
The problem I am having is that despite having set the top bar and bottom bar simulated metrics attributes to Opaque Navigation Bar and Opaque Tab Bar respectively, See:
When the app builds and runs the top of the UIView is always underneath the nav bar. My over all feeling is that this is somehow a constraints issue but I have not been able to find the solution to it. How do I set the constraints so that the UIView is always immediately underneath the nav bar, and the bottom of the view is always just on top of the tab bar?
Select your UIView in storyboard and assign constraints to the top margins and to bottom margins. There is a 'Pin' button you use to do this that looks something like a Tie-Fighter ship in Star Wars, it is located at the bottom right of your storyboard view.
This will set margins to stretch to top and bottom always.
That is what the layout guides are for. Pin the top to the Top Layout Guide and the bottom to the Bottom Layout Guide. The guides will always move to adjust for any top and bottom bars.

Autolayout adding extra padding

I have a UITableViewController in a Storyboard that I'm adding as a subview to a lone UIView in a UIViewController, my end goal is to get the UITableView flush up against the status bar so that scrolling goes underneath the status bar (not through it with clashes).
I have configured the lone UIView to have constraints of 0 on both verticals and horizontals but as demonstrated in the image I believe autolayout is then adding the 20px y offset that I am including in the layout. If I remove the 20px y offset (and size the UIView to the whole layout) I end up with the clashing.
I suggest you to set up your view controller as follows. Create a UIViewController in IB and add a simple UITableView as a subview of its main view. I almost never use the UITableViewController because it has almost no added value but it restricts you in adding subviews to your table view. Now, you position your table view's origin to (0, 20) and set up the top layout constraint of the table view to the top layout guide instead of the superview. Maybe you should open the drop down menu close to the constraint constant value in IB:
This way your table view will start right under the status bar.
Note however that iOS 7 design guidelines suggest that you would in fact extend the content under the top bars (nav bar and status bar). You should create a 20 points high semi-transparent background png, position it under the status bar, and leave the table view to scroll under the status bar. In this case you should also not forget to check in the "Adjust scroll views inset" option of your view controller.

Resources