Reputation: 770
I'm trying to make an animation with a view to simply move up the Y axis by about 50 points. The animation works, but as soon as its done, it will return back to its original position.
UIView* view = [self.view viewWithTag:50];
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationOptionCurveEaseOut
animations:^
{
CGRect frame = view.frame;
frame.origin.y = 230;
frame.origin.x = 30;
view.frame = frame;
}
completion:^(BOOL finished)
{
NSLog(@"Completed");
}];
Upvotes: 2
Views: 1232
Reputation: 571
For completeness, constraints need to be changed and updated in the the animation as seen below:
- (IBAction)moveAction:(id)sender {
self.spaceConstraint.constant += 220;
[UIView animateWithDuration:0.5 animations:^{
[self.imageView layoutIfNeeded];
}];
}
Upvotes: 0
Reputation: 5347
Your layout constraints will be pulling it back. This is a really common question at the moment. You have to modify your NSLayoutConstraint objects to reflect the change to the view.
E.g. Constraint.constant += 50;
Search stack overflow for other questions like the one you want to ask before asking.
Upvotes: 2