alionthego
alionthego

Reputation: 9743

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.

Upvotes: 1

Views: 1028

Answers (2)

alionthego
alionthego

Reputation: 9743

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:

  1. check Hide Bottom Bar on Push on storyboard

  2. 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)

  3. Then finally if you are using an inputAccessoryView, add layoutIfNeeded() in the override to the getter as I have done above.

Upvotes: 2

Hanny
Hanny

Reputation: 1342

In Xcode7 you have to right click your element, draw a line to the bottom until the constraint selector pops up. Constraint selector

enter image description here

Then press ALT and now you'll get the desired Bottom constraint

enter image description here

Upvotes: 1

Related Questions