Skip to content

Instantly share code, notes, and snippets.

@ethanbing
Created November 5, 2014 04:20
Show Gist options
  • Save ethanbing/3ff9ab56cab5b0edc2fc to your computer and use it in GitHub Desktop.
Save ethanbing/3ff9ab56cab5b0edc2fc to your computer and use it in GitHub Desktop.
UICollectionView 点击空白 继续传递事件
继承并实现
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
NSIndexPath * tappedCellPath = [self indexPathForItemAtPoint:touchPoint];//获取点击处的cell的indexPath
if (tappedCellPath == nil) {
[[self nextResponder] touchesEnded:touches withEvent:event];
}else{
[self.delegate collectionView:self didSelectItemAtIndexPath:tappedCellPath];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment