Search code examples
iosobjective-cimageanimationuiimageview

How to animate UIImageView scale but keep its image unchanged?


I have a circle UIImageView with a user picture as an image.
I need to implement an animation - to make it possible to scale UIImageView down/up but keep its image unchanged.
I have tried the following code:

[UIView animateWithDuration: 2.0f animations: ^{
    self.myImageView.transform = CGAffineTransformMakeScale(0.5f, 0.5f);
}];

But it changes the image scale too. I think this is expected behavior, so I need help - how to implement such kind of animation? (Scale only UIImageView and keep image unchanged)


Solution

  • You should animate myImageView.frame or myImageView.bounds instead. Be sure the contentMode is set to something that does not scale the image, such as top left or center.