1
votes

I have an app whose UI is set up like this

V:[statusBarView][contentView][footerView]

though I did the layout in IB (see below). statusBarView and footerView have their heights pinned, and their top/bottom spaces (respectively) are flush with the parent view (the VC's view).

In the screen grabs you can see that when the screen rotates and the view's redraw, the middle contentView container and it's subviews are resized and laid out correctly.

I have the action for one of these buttons set to resize the (blue) footerView. My expectation, since the constraints are set up such that the bottom of the contentView is equal to the top of the footerView, is that if I resize the footer, the contentView will handle it's resizing on it's own. This is not happening. Regardless of if I make the footerView taller or shorter or move it up or down, the contentView remains unchanged.

I have tried setNeedsUpdateConstraints, setNeedsLayout, etc, but they have no effect.

Perhaps I'm completely missing the point of Auto Layout, or just how to implement it. Why would the views be able to get the layout correct when the window/superview changes, but not the sibling views that the constraints actually depend on?

Thanks

Default vertical layoutDefault horizontal layout

2

2 Answers

0
votes

When you are trying to resize the footer, are you just setting the frame, or are you updating the constraints?

You should be able to replace the height constraint with a new one (that has the updated height). In the code below I'm using this technique to change the leading value on a view called _leftNavBar that sites directly in self.view. You should be able to modify it pretty easily to find the height constraint, and set the new value on it.

[self.view.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *con, NSUInteger idx, BOOL *stop) {
    if ([con.firstItem isEqual:_leftNavBar]
        && [con.secondItem isEqual:self.view]
        && con.firstAttribute == NSLayoutAttributeLeading
        && con.secondAttribute == NSLayoutAttributeLeading) {
        [self.view removeConstraint:con];
    }
}];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_leftNavBar
                                                      attribute:NSLayoutAttributeLeading
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeLeading
                                                     multiplier:1.0f
                                                       constant:(newLeftNavX - self.getLeftNavBarWidth)]];
[self.view setNeedsUpdateConstraints];
0
votes

Define an IBOutlet to have a reference to the footer's height constraint. When changing it's value, it should change the content view's height too.