Search code examples
iosobjective-cautolayout

Changing the connecting point of an AutoLayout constraint?


I have the following setup within my app. There is a footer bar that has a number of buttons on, above that there is a UIImageView that currently has the constraints set to 10,10,10,10 for all edges. I have added an image below to show the constraint.

enter image description here

Now what I would like to do is when a button on the footer bar is clicked a new "sub bar" will appear between the footer bar and the UIImageView. My question is how do I adjust the constraint so that the bottom anchor is connected to the new sub bar and not the footer. In a sense it pushes the UIImageView up to make way for the new bar?

I don't want the new bar to go over the UIImageVIew, instead I want to push it up with an animation.


Solution

  • Create that bar between the imageview and the footer and layout it properly then make its height constarint = 0 to be hidden at first, then control darg this constarint as IBOutlet and when you want to show change its constant to say 100 and call:

    [self.view layoutIfNeed];
    

    Put it in a UIView animation if you want it animated.