The animation by itself works when I use a constraint on the distance between the UIImageView and the top of the parent UIView without vertical and horizontal centering.
The constraints on the UIImageView:
- Width: 240
- Height: 128
- Top space to Top Layout: 200 --> connected to logoImageViewVerticalSpaceConstraint
The animation works great when I use this:
self.logoImageViewVerticalSpaceConstraint.constant = 20;
[UIView animateWithDuration: 1.0
delay: 0
options:(UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{[self.logoImageView layoutIfNeeded];}
completion:^(BOOL finished) {NSLog(@"Finished animation"); }];
The issue kicks in when I don't want to use a static space to top layout constraint because the imageview needs to be centred for 3.5 and 4 inch devices. To solve this I thought starting off with a vertical and horizontal center constraint.
- Width: 240
- Height: 128
- Align center x to: superview --> connected to logoImageViewYCenterConstraint
- Align center y to: superview
Now I thought I could simply remove the y center constraint and adding the space to top layout constraint of 20pt myself:
[self.logoImageView removeConstraint:self.logoImageViewYCenterConstraint];
NSLayoutConstraint *topSpaceConstraint = [NSLayoutConstraint
constraintWithItem:self.view attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual toItem:self.logoImageView
attribute:NSLayoutAttributeTop multiplier:1
constant:20];
[self.view addConstraint:topSpaceConstraint];
[UIView animateWithDuration: 1.0
delay: 0
options:(UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{
[self.logoImageView layoutIfNeeded];
}
completion:^(BOOL finished) {
NSLog(@"Finished animate");
}];
The result is that the UIImageView stays centred and it blows up a bit. Which is the total opposite of what I expect to happen because I removed the x center constraint. Added the top constraint with distance 20pt to the top of the parent UIView and I did not touch any other constraints (like the width and height).