0

I have a TabBarController with 4 tabs.

One of the tabs has a UIView that has several labels & buttons.

This UIView itself has a constraint 'Top' to Top Layout Guide Bottom set to 88.

This is the distance to the navigation bar.

I have a case where I need to remove some of the other tabs at run time which I do on the TabBarController viewDidLoad using:

tabBarViewControllers?.removeAtIndex(index)

The problem I have is that if I remove any of the other tabs, the above constraint is "lost" as soon as I try to interact with the Tab screen.

Any idea what might "break"/change the constraint? There are no error messages and looking at the X,Y coords it looks as if the constraint is adjusted to the top of the tab as if there was no navigation bar (although it is clearly visible on the screen).

Update: After a closer examination of X, Y coordinates when launching the TabBarController with all tabs and w/o some of the tabs, it is 100% clear that the when removing the tabs I am 'losing' the height of the status bar and the height of the navigation bar resulting in the view's Y coordinate being 80 rather than 152 (= 80 + 44 (navbar) + 22 (status bar) + 6 (padding set somewhere else) ).

While in theory I could hard-code the offset to 152, I'd rather understand why am I losing the "heights" of the navigation bar and the status bar...

zevij
  • 2,090
  • 1
  • 20
  • 25
  • I tried with the constant of 88 (which is what I needed) and it did not work. Why are you suggesting a constant of 0? – zevij Jul 03 '16 at 08:36

1 Answers1

0

Found a similar issue here. Although it did not solve my problem (I am not using scrollView), it made me think again about how I set the constraint.

To solve my problem, I set the vertical distance to the main view as oppose to the navbar (I used the pin menu in storyboard and set the vertical constraint to it).

Community
  • 1
  • 1
zevij
  • 2,090
  • 1
  • 20
  • 25