这是我的
UICollectionViewController - UICollectionViewCell -UIScrollView - 图片 View
我正在尝试处理 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]];
}
最佳答案
单元格的 ImageView 应首先允许用户交互以检测点击。确保使用以下行启用用户交互。
[cell.imageView setUserInteractionEnabled:YES];
关于ios - 手势识别器从不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16070616/