我通过继承UICollectionView和UICollectionFlowLayout来实现单行轮播视图。视觉效果类似于以下内容:
我想只启用中间单元格上的触摸并禁用其余单元格。目前,我将启用/禁用逻辑放在委托类中,如下所示:
- (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;
}
我想把这个逻辑移到我的UICollectionView子类中,因为它感觉更整洁。那么,有没有办法拦截我的UICollectionView子类中的委托调用并添加上面的逻辑?