本文介绍了在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未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:11