So I have an UICollectionView
and I want the user to be able to pinch out or in to either expand and collapse a collection cell. I used this tutorial to perform the expanding and collapsing bit. Which works. I then added the code below to my collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
delegate method.
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchCollection:)];
[cell addGestureRecognizer:pinchGesture];
Then created the action pinchCollection:
like this:
-(void)pinchCollection:(id)sender {
UIPinchGestureRecognizer *gesture = (UIPinchGestureRecognizer*)sender;
if (gesture.state == UIGestureRecognizerStateBegan) {
if (gesture.scale <= -1) { // I also changed this to be gesture.scale < 1 but it didn't work.
// pinch in
[self collapseCollection];
gesture.scale = 1;
}
if (gesture.scale >= 1) { // I changed this to be gesture.scale > 1 but it didn't work either.
// pinch out
[self expandCollection];
gesture.scale = -1;
}
}
}
But only the pinching out code works. I have searched for a tutorial or code that refers how to do this properly but with no luck.
Expanding a collection looks like this: