3

我有一个UIImageViewUITableViewCell. 我正在尝试添加单击手势以全尺寸查看它,并添加双击手势来喜欢。这是我的代码:

    UITapGestureRecognizer *aSingleTapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SingleTapGestureRecognizer:)] autorelease];
    aSingleTapGesture.delegate = self;
    aSingleTapGesture.numberOfTapsRequired = 1;
    [cell.imgProductImage addGestureRecognizer:aSingleTapGesture];

    UITapGestureRecognizer *aDoubleTapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapGestureRecognizer:)] autorelease];
    aDoubleTapGesture.delegate = self;
    aDoubleTapGesture.numberOfTapsRequired = 2;
    [cell.imgProductImage addGestureRecognizer:aDoubleTapGesture];

它只调用单击手势,而从未调用过双击手势。比我require to fail在单击手势上使用的还要多。

   [aSingleTapGesture requireGestureRecognizerToFail:aDoubleTapGesture];

好吧,使用这段代码我可以同时调用单击和双击手势,但问题是tableView:didSelectRowAtIndexPath:也被调用了。如果我的手势被调用,我不想调用 didSelectRowAtIndexPath。据我了解,之所以调用它是因为单击手势正在等待双击手势意味着在调用 didSelectRowAtIndexPath 时。

请提供任何帮助。

4

3 回答 3

1

您可以在 tableview 单元格中使用 UIButton 而不是 UIImageView 。使用以下代码获取单击和双击。

//add target for your UITableViewCell's button

[aBtnThumbObj addTarget:self action:@selector(btnThumbClickDouble:) forControlEvents:UIControlEventTouchDownRepeat];

[aBtnThumbObj addTarget:self action:@selector(btnThumbClickSingle:) forControlEvents:UIControlEventTouchUpInside];

-(void)btnThumbClickSingle:(UIButton*)sender
{
    [self performSelector:@selector(singleTapOnButtonSelector:) withObject:sender afterDelay:0.2];
}
-(void)btnThumbClickDouble:(UIButton*)sender
{   
   [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapOnButtonSelector:) object:sender];
//Your implementation for double tap
}
-(void)singleTapOnButtonSelector:(UIButton*)sender
{
//Your implementation for single tap
}
于 2013-06-11T09:46:49.063 回答
1

您可以将单元格的选择样式设置为

cell.selectionStyle = UITableViewCellSelectionStyleNone;

然后只是不实现你的 -tableViewDidSelectRowAtIndexPath 方法

于 2013-06-11T10:10:12.437 回答
0

这两行代码对我有用:

tapGesture.cancelsTouchesInView = YES;
tapGesture.delaysTouchesBegan = YES;
于 2015-04-23T07:37:18.477 回答