手势识别器永远不会发射

时间:2013-04-17 21:31:39

标签: ios cocoa-touch uikit uigesturerecognizer

这就是我所拥有的

UICollectionViewController    - UICollectionViewCell       - UIScrollView         - ImageView

我正试图处理在imageview上的点击但从未被调用。

UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[cell.imageView addGestureRecognizer:tap];

- (void)handleTap:(UITapGestureRecognizer *)recognizer  {
    NSLog(@"Tap");
    NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:[recognizer locationInView:self.collectionView]];
}

1 个答案:

答案 0 :(得分:2)

单元格的ImageView应该首先允许用户交互来检测点击。确保使用以下行启用用户交互。

[cell.imageView setUserInteractionEnabled:YES];