UITablevlewCell 内 UIImageView 上的 UITapGestureRecognizer 未被调用
我目前有一个自定义 UITableViewCell,其中包含 UIImageView 并尝试在 UIImageView 上添加 UITapGestureRecognizer,但没有成功。这是代码片段。
//within cellForRowAtIndexPath (where customer table cell with imageview is created and reused)
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[imageView addGestureRecognizer:tap];
[tap release];
// handle method
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {
RKLogDebug(@"imaged tab");
}
我还在单元格和 UIImageView 的超级视图上设置了 userInteractionEnabled 但仍然没有运气,有什么提示吗?
编辑:
我还通过 cell.selectionStyle = UITableViewCellSelectionStyleNone; 删除了单元格的选择;这可能是个问题吗
I currently have a custom UITableViewCell which contains a UIImageView and trying to add a UITapGestureRecognizer on the UIImageView with no luck. here is snippet of the code.
//within cellForRowAtIndexPath (where customer table cell with imageview is created and reused)
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[imageView addGestureRecognizer:tap];
[tap release];
// handle method
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {
RKLogDebug(@"imaged tab");
}
I've also set userInteractionEnabled on the cell and the superview of the UIImageView but still no luck, any hints?
EDIT:
I've also remove cell's selection by cell.selectionStyle = UITableViewCellSelectionStyleNone; Could this be a problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UIImageView 的用户交互默认情况下处于禁用状态。您必须显式启用它才能响应触摸。
UIImageView's user interaction is disabled by default. You have to enable it explicitly to make it respond to touches.
Swift 3
这对我有用:
Swift 3
This worked for me:
就我而言,它看起来像:
和选择器:
In my case it looks like :
And selector :