Drag over UICollectionViewCells to select iOS
<p>I am trying to replicate the iOS9 feature where you can drag to select multiple photos, or UICollectionViewCells: <a href="https://i.ytimg.com/vi/LZRTu3B5zlY/maxresdefault.jpg" rel="nofollow noreferrer">https://i.ytimg.com/vi/LZRTu3B5zlY/maxresdefault.jpg</a></p>

<p>I saw <a href="https://stackoverflow.com/questions/27390728/uicollectionview-drag-finger-over-cells-to-select-them">one answer here</a>, but as a beginner iOS and objective-c developer, I couldn't figure out what to do.</p>

<p>I have also tried to work from <a href="https://stackoverflow.com/questions/20357960/drawing-selection-box-rubberbanding-marching-ants-in-cocoa-objectivec">this question</a>, but I couldn't get anything to select.</p>

<p>I tried some code, but couldn't get any response at all.</p>

<pre><code>- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    self.startPoint = [touch locationInView:self.collectionView];
    self.selectionBox = CGRectMake(self.startPoint.x, self.startPoint.y, 0, 0);
    [self.collectionView setNeedsDisplay];
}

- (void)touchesMoved:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self.collectionView];
    _selectionBox.size.width = currentPoint.x - (self.selectionBox.origin.x);
    _selectionBox.size.height = currentPoint.y - (self.selectionBox.origin.y);
    self.selectionBox = CGRectMake(self.startPoint.x, self.startPoint.y, 0, 0);
    // select all the cells in this selectionBox area
    [self.collectionView setNeedsDisplay];

}
</code></pre>

<p>Any pointers on how to code this? Thanks very much.</p>