First, you should not animated views in viewDidLoad
. You should start animation in viewWillAppear
or viewDidAppear
.
What was said in the comments is correct, you should not be modifying frames directly when autolayout is enabled. Any constraint update or layout pass that comes will reset the frames to their original values. What you should do is modify the constraints themselves that are in place. If you add these constraints in code, perhaps save the ones necessary for animation as properties and modify them in the animation setup method. If you set up your view in Interface Builder, you can create outlets of constraints in the code and access them that way. Remember to call [self.view layoutIfNeeded]
inside your animation block to actually trigger a constraint update and layout pass.
-(void)animationCode{
CGRect imageFrame = self.imageViewLogo.frame;
[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.imageViewLogoYConstraint.constant -= 150;
[self.view layoutIfNeeded];
} completion:nil];
}
Where, imageViewLogoYConstraint
is a constraint example that has been set up somewhere.