I am implementing a single row carousel view by subclassing UICollectionView and UICollectionFlowLayout. The visual looks similar to the following:
I want to only enable touch on the middle cell and disable the rest. Currently, I put the enabling/disabling logics in the delegate class as follow:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kButtonCollectionViewCellIdentifier
forIndexPath:indexPath];
// ...
cell.userInteractionEnabled = NO;
return cell;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
CGPoint midPoint= CGPointMake(self.collectionView.center.x + self.collectionView.contentOffset.x,
self.collectionView.center.y + self.collectionView.contentOffset.y);
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:midPoint];
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
cell.userInteractionEnabled = YES;
}
I would like to move this logics into my UICollectionView subclass, as it feels neater. So, is there a way for me to intercept the delegate calls in my UICollectionView subclass and add the above logics?