Reputation: 9426
I'm trying to get used to animation with Autolayout and constraints instead of animation with frames. In my project I have a UIView
near the top of the screen that I'm trying to animate straight downward (y position). I understand that I must modify the constraint constant value, but doing so decreases the height of my view instead of "pushing" it downward like I'm wanting. Here's my code:
self.topConstraint.constant = 180;
[UIView animateWithDuration:0.5f animations:^{
[self.theView layoutIfNeeded];
} completion:^(BOOL finished) {
}];
topConstraint
is a vertical space constraint between the top of the ViewController's view and theView
.
Other constraints on theView
include:
Center X Alignment
Horizontal Space
Vertical Space (self.topConstraint
)
Vertical Space (represents the space between theView
and the bottom of the ViewController's view)
Pinned width
Pinned height
How do I modify the constraint values to simply change the position of theView
without affecting its width/height?
Upvotes: 0
Views: 1771
Reputation: 119031
You should remove the constraint:
Vertical Space (represents the space between theView and the bottom of the ViewController's view)
because you don't want the height to change (you have it pinned) and you are specifying the x (centre constraint) and y (other vert constraint) positions with other constraints so it isn't required.
Your Horizontal Space
constraint may also not be required (because you have a Center X Alignment
constraint) - the horizontal space could be required, but more likely on the view that this one is centred on.
Upvotes: 2