我在UICollectionView
中有一系列UICollectionViewCell
UICollectionViewFlowLayout
。
每个单元格包含一个UIImageView
,取决于indexPath大于单元格本身。单元格不会剪切其内容,因此您始终可以看到整个图像。
但我不能在细胞框架外进行触摸,而是在图像内部进行正常触摸并触发细胞选择。
我尝试覆盖hitTest:withEvent
的方法pointInside:withEvent
和UICollectionViewCell
,但它没有任何变化。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (CGRectContainsPoint(self.imageView.frame, point)) {
NSLog(@"Contains: %d", cellIndex);
return self;
}
NSLog(@"Doesn't contain: %d", cellIndex);
return [super hitTest:point withEvent:event];
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
if (CGRectContainsPoint(self.imageView.frame, point)) {
NSLog(@"Inside: %d", cellIndex);
return YES;
}
NSLog(@"Outside: %d", cellIndex);
return NO;
}
当我在屏幕上显示集合视图的前3个元素时,我会点击第三个元素(在它的单元格框架之外,但在UIImageView内部),这就是它的痕迹:
2013-05-06 10:53:38.395 Contigo[3351:c07] Doesn't contain: 0
2013-05-06 10:53:38.395 Contigo[3351:c07] Outside: 0
2013-05-06 10:53:38.396 Contigo[3351:c07] Contains: 2
2013-05-06 10:53:38.396 Contigo[3351:c07] Doesn't contain: 0
2013-05-06 10:53:38.396 Contigo[3351:c07] Outside: 0
2013-05-06 10:53:38.396 Contigo[3351:c07] Contains: 2
2013-05-06 10:53:38.396 Contigo[3351:c07] Doesn't contain: 0
2013-05-06 10:53:38.396 Contigo[3351:c07] Outside: 0
2013-05-06 10:53:38.397 Contigo[3351:c07] Contains: 2