本文介绍了UITablevlewCell 内 UIImageView 上的 UITapGestureRecognizer 未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个自定义 UITableViewCell,其中包含一个 UIImageView 并尝试在 UIImageView 上添加一个 UITapGestureRecognizer,但没有成功.这是代码片段.

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");
}

我还在单元格和 UIImageView 的超级视图上设置了 userInteractionEnabled 但仍然没有运气,有什么提示吗?

I've also set userInteractionEnabled on the cell and the superview of the UIImageView but still no luck, any hints?

编辑:

我还通过 cell.selectionStyle = UITableViewCellSelectionStyleNone; 删除了单元格的选择;这会不会是个问题

I've also remove cell's selection by cell.selectionStyle = UITableViewCellSelectionStyleNone; Could this be a problem

推荐答案

UIImageView 的 用户交互在默认情况下禁用.您必须显式启用它以使其响应接触.

UIImageView's user interaction is disabled by default. You have to enable it explicitly to make it respond to touches.

imageView.userInteractionEnabled = YES;

这篇关于UITablevlewCell 内 UIImageView 上的 UITapGestureRecognizer 未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:48