Search code examples
iosuiimageviewcore-animationuiviewanimation

iOS: How to move an image inside a UIImageView


I have an UIImageView that's showing part of an image. Is there a way that I can animate the UIImageView so that the image in it moves? So I wish to have my UIImageView stay in it's position but the image in it move. Any way of doing it?


Solution

  • No, but the way you usually do this is by adding your UIImageView to a UIScrollView. Make the scroll view as large as you want the displayed image to be but make its contentSize and the image view in it as large as they need to be.

    Now you can animate the scroll position of the scroll view to smoothly animate the image position / crop.