0
votes

I want to make the width of an UIImageView larger through an animation. I have an UIView with and UIImageView made in the story board. What I want to achieve is so that it looks like the view is scaling from left to right, and keeping its original position. I have tried the following code, but what it does is animating the imageview from the top left corner of its parent view and moving and scaling it until it reaches the position and scale it had from the beginning.

[UIView animateWithDuration:4.0f delay:1.0f options:UIViewAnimationCurveEaseOut animations:^{
    CGRect currentFrame = self.imageview1.frame;
    currentFrame.size.width = 150;
    self.imageview1.frame = currentFrame;
}completion:nil];

Any ideas why this behaviour?

1
I noticed that when disabling autolayout for the entire story board, the animation way playing correctly. However, is there a way to achieve this without having to disable the autolayout?Mike
if you don't get enough attention on your question it might be worth it to assemble a tiny sample project demonstrating your problem and then put it on GitHub for people to try out.Michael Dautermann

1 Answers

0
votes

A bit late answer, but I solved the problem. It seems that you cannot change the frame of views in code if autolayout is enabled. Instead you need to animate the constraints of the view, which you can set up in the storyboard and then animate like this:

[self.view layoutIfNeeded];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

    self.bottomViewY.constant = -196;

    [self.view layoutIfNeeded];

} completion:nil];

self.bottomViewY is a constraint which is assigned as an IBOulet. You need to call layoutIfNeeded as it will update the constraints.