Reputation: 48
I have a view and I want to move it according to its top spacing constraint inside the animation block.
This is the code I use. The constraint is changing, but the frame is still the same; what should I do?
I have an IBOutlet
to the constraint named: topConstraint
[UIView animateWithDuration:0.3f animations:^{
self.topConstraint.constant -= 80 ;
[self.view layoutIfNeeded];
}];
I have read everything about this, but it doesn't seem to work.
Upvotes: 2
Views: 2218
Reputation: 16062
This is what it worked for me in Swift 3
self.view.setNeedsUpdateConstraints()
UIView.animate(withDuration: 1.0,
animations: {
self.horizontalCenterConstraint.constant = -23
self.view.layoutIfNeeded()
}, completion: nil)
Upvotes: 1
Reputation: 199
self.topConstraint.constant = newValue;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration: animationDuration
delay: animationDelay
options: UIViewAnimationOptionCurveEaseOut
animations: ^(void)
{
[self.view layoutIfNeeded];
}
completion: nil];
Upvotes: 0