Search code examples
iosautolayoutuitabbarcontrollersafearealayoutguide

UITabbarController hide tab bar breaks safe area layout


I'm having a frustrating time getting an auto layout issue to work. Hopefully some fresh eyes on the problem will be better at finding a solution...

I have a UITabBarController in a storyboard file, and in the first view controller there is a MKMapView and a button: This is how the view looks initially in portrait mode, as it should.

The button is constrained to the bottom of the View Controller's view's safe area. The MKMapView is constrained to its superview. And this works fine so far.

The problem comes when I rotate the phone. In the UITabBarController's viewWillTransitionToSize:withTransitionCoordinator: method, I call [self.tabBar setHidden:(size.height < kMinViewSize)] in order to hide the tab bar when the view's height is too small.

After hiding the tab bar, this is what I get: Tab bar is hidden, but neither the map view nor button shift to fill the void

And then when I rotate back to portrait mode again, the tab bar unhides as it should, but the layout gets screwed up once again: Tab bar unhidden, now it covers the map view and button

And, finally, if I select another tab, then come back to the map tab, the button moves back to the correct location.

Am I missing something obvious? Thanks in advance for your help!


Solution

  • Well, I figured it out and it wasn't anything too obvious. The self.tabBar setHidden: call was contained in the animation block of [coordinator animateAlongsideTransition:]. I took the animation block out, and everything worked fine.

    Thank you, Andre Slotta for your comment-- that at least helped me realize something was wrong in the code if not in the storyboard.