Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm assuming you're using the default UICollectionViewDelegateFlowLayout, right? Then make sure you respond accordingly to the delegate methods, and when the pinch gesture occurs, simply invalidate the layout.</p> <p>For example, if I want to adjust the size of every item, while pinching:</p> <pre><code>@interface ViewController () &lt;UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout&gt; @property (nonatomic,assign) CGFloat scale; @property (nonatomic,weak) IBOutlet UICollectionView *collectionView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.scale = 1.0; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; UIPinchGestureRecognizer *gesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(didReceivePinchGesture:)]; [self.collectionView addGestureRecognizer:gesture]; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(50*self.scale, 50*self.scale); } - (void)didReceivePinchGesture:(UIPinchGestureRecognizer*)gesture { static CGFloat scaleStart; if (gesture.state == UIGestureRecognizerStateBegan) { scaleStart = self.scale; } else if (gesture.state == UIGestureRecognizerStateChanged) { self.scale = scaleStart * gesture.scale; [self.collectionView.collectionViewLayout invalidateLayout]; } } </code></pre> <p>The property <code>self.scale</code> is just for show, you can apply this same concept to any other attribute, this doesn't require a beginUpdates/endUpdates because the user himself is carrying the timing of the scale.</p> <p><a href="https://github.com/CanTheAlmighty/SamplePinchGesture">Here's a running project</a>, in case you want to see it in action.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload