Let's say I have an UIImageView
which is significantly smaller than the image it's showing. I set contentMode
to UIViewContentModeScaleAspectFill
to make it look like you're seeing only a specific part of the image. It automatically shows the center of the image.
I don't want to use the other contentMode
s like top, bottom, etc because in my app you can drag the imageView and as you move it, it shows the parts of the image that are under the imageView. In other words the imageView is like a window to the image itself.
How can I change which part of the image the imageView is showing?
Thanks!
Various possibilities here:
Don't use a UIImageView. Use a normal view and manipulate its layer. Give the layer content and use its contentsRect
to describe which part of the view should be visible.
Do use a UIImageView. Show the whole image. Put the image view inside a scroll view. Let the user drag to scroll. (A scroll view is a "window" to what's inside it.)
The second one is easier because the scroll view responds to dragging, whereas with the first possibility you'd have to detect dragging separately and keep setting the contentsRect
in response, thus reinventing the wheel.