UICollectionView and images
-
14-07-2021 - |
Question
I have a UICollectionView
, and it works great, but I have a doubt.
In my view I have a UICollectionViewCell
and inside that I have a UIImage.
The cell is linked to a blank view controller, and inside that I have a UIScrollView
(for managing the zoom) and a UIImage
(the full-size image).
I wondered if there was some delegate or something that could handle the image opening process automatically (with zoom, etc.).
Now I'm handling the zoom effect with UIScrollViewDelegate
delegate and method viewForZoomingInScrollView:
... but the result is very poor, definitely not fluid!
Solution
There's no built in view for doing what you want, no. You're doing the right thing with a UIImageView
inside UIScrollView
. If it's not very fluid, then it's likely because your image is huge. The way to get around that is to load different images for different zoom levels. So as you zoom in, listen to the UIScrollViewDelegate
method called scrollViewDidZoom:
and change the image to better resolution as you zoom in. Or, take a look at CATiledLayer
.
Note that this has nothing to do with your UICollectionView
.