1

I'm trying to shift to Auto Layout in my app, but I'm having some trouble with my UITabBarController. Basically, I have two buttons on my home screen, and I want them to have equal sizes, one 50 pixels from the top of the screen and one 50 pixels from the bottom.

The issue is that when I do this:

NSArray* verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-
    [buttonOne(150)]" options:0 metrics:nil 
    views:NSDictionaryOfVariableBindings(buttonOne)];
[self.view addConstraints:verticalConstraints];

verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:
    [buttonTwo(==buttonOne)]-50-|" options:0 metrics:nil 
    views:NSDictionaryOfVariableBindings(buttonOne, buttonTwo)];
[self.view addConstraints:verticalConstraints];

The bottom button is 50 pixels from the bottom of the view, which is 568 points tall, when the height of self.view should be the screen height minus the tab bar's height (the navigation bar is hidden). The majority of this padding is eaten up by the height of the tab bar.

My questions is: Why is my view controller's view not resizing so that it doesn't count the space under my tab bar as part of its height?

eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
  • See [Status bar and navigation bar appear over my view's bounds in iOS 7](http://stackoverflow.com/questions/17074365/status-bar-and-navigation-bar-appear-over-my-views-bounds-in-ios-7) – Hackless Oct 10 '13 at 16:45

2 Answers2

0

Suggestion would be to make sure you adding your constraints to a container and not a top level view. ie. Add a view under the top level view and add components to that. My guess is that there are some autoresizing contraints on the top level view

railwayparade
  • 5,154
  • 1
  • 39
  • 49
0

I think railwayparade is correct. I implemented a UITabBar/UITabBarController replacement using auto-layout, it's called GGTabBar. I also wrote a pretty comprehensive Blog Post about how I approached the problem, and how did I use Auto Layout to solve it.

Goles
  • 11,599
  • 22
  • 79
  • 140