is possible to zoom in/out a UIImageView in custom cell of a UICollectionView only when pinch the cell's imageView?

BetterCallSaul picture BetterCallSaul · Nov 5, 2015 · Viewed 7.4k times · Source

I have a CollectionView that have one custom cell.

I want to zoom in/out imageView in cell, so i add pinch gesture at CollectionView.m

when i add gesture to self.collectionView, like this:

[self.collectionView addGestureRecognizer:pinchGesture];

it works! my cell.imageView can zoom in/out, but when i pinch other place(not in cell's imageView, my cell.imageView still zoom in/out with the gesture, I want the cell.imageView zoom in/out just when user pinch the cell.imageView, so i try to add gesture use this code:

[cell.imageView addGestureRecognizer:pinchGesture];

but unfortunately it doesn't work. Nothing happen when i pinch the cell's imageView.

so my question is, is possible to zoom in/out the cell's imageView only when user pinch the cell's imageView? not other place.

Answer

Marc-Alexandre Bérubé picture Marc-Alexandre Bérubé · Nov 5, 2015

By default, Image view's property userInteractionEnabled is set to NO, which disable all gesture recognizers. Setting the property to YES should solve your problem