2

我在 aUICollectionView中有一系列UICollectionViewCells UICollectionViewFlowLayout

每个单元格都包含一个UIImageView,取决于 indexPath 是否大于单元格本身。单元格不会剪切其内容,因此您始终可以看到整个图像。

但是我不能在单元格框架之外进行触摸,而是在图像内部进行触摸,以充当正常触摸并触发单元格的选择。

我尝试覆盖方法hitTest:withEventpointInside:withEventUICollectionViewCell它没有改变。

- (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
4

0 回答 0