13

Is there any method make the UICollectionView zoomable, i.e. when you pinch, all the cells can be zoomed in and out.
I can implement this in UIScrollView by returning the only subview of the UIScrollView from delegate method

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView

Since UICollectionView is kind of UIScrollView, is there a way or work around to implement this? Does the UICollectionView has one direct subview that contains all cells?
Thanks

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
yibuyiqu
  • 728
  • 1
  • 7
  • 20

1 Answers1

16

I think what you're asking for looks like what is done in the WWDC1012 video entitled Advanced Collection Views and Building Custom Layouts (demo starts at 20:20).

You basically have to add pinchGesture to you UICollectionView, then pass the pinch properties (scale, center) to the UICollectionViewLayout (which is a subclass of UICollectionViewFlowLayout), your layout will then perform the transformations needed to zoom on the desired cell.

luk2302
  • 55,258
  • 23
  • 97
  • 137
vitaminwater
  • 6,934
  • 3
  • 19
  • 23
  • 3
    I tried taking this route, but the cell will disappear once it gets bigger than the collectionView – runeb Dec 17 '12 at 13:01
  • This happens to me as well. I have screen-sized UITableViewCells, and I can scale them down, but scaling them up makes them disappear. – Jacob Jan 28 '13 at 00:32
  • 3
    You can override "collectionViewContentSize" to make it scale with the cell. – Hai Feng Kao May 19 '13 at 01:15
  • Here is the link to the video. You have to log in. [WWDC102 videos](https://developer.apple.com/videos/wwdc/2012/) Then, look for the section labeled "Advanced Collection Views and Building Custom Layouts" like @stant said above – William Grand Oct 17 '13 at 19:12
  • 3
    In the video, the section on adding pinch scaling starts at 20:20. Note – the technique as given shows how to add scaling to one cell in the collection view, rather than all cells, as requested by OP. – Benjohn Jan 02 '14 at 13:35
  • What if you are not using the flow layout but a custom implementation? – ShivamD Aug 06 '14 at 23:34
  • Well then it's up to you;), but you can clearly get inspiration from what is described in the video. – vitaminwater Aug 07 '14 at 11:28
  • 1
    here's an example with code http://stackoverflow.com/questions/16406254/zoom-entire-uicollectionview – Cbas Sep 19 '16 at 22:39