UITongPress上的UILongPressGestureRecognizer - 双重调用

Rui*_*pes 4 uitableview uigesturerecognizer ios

我在一个单元格中使用UILongPressGestureRecognizer.我需要的是:当用户点击一个单元格1.0秒时,调用一个视图控制器.如果用户点击该单元格,则另一个VC.

我可以通过使用UILongPressGestureRecognizer来实现这一点.但问题是调用viewController两次.

码:

if (indexPath.section == 0 && indexPath.row == 1){
    UILongPressGestureRecognizer *longPressTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(memberListWithSearchOptions)];

    longPressTap.minimumPressDuration = 1.0;

    [cell addGestureRecognizer:longPressTap];
    [longPressTap release];
}
Run Code Online (Sandbox Code Playgroud)

我认为我需要的是,在识别出LongPress后,禁用识别器,直到tableView再次出现在屏幕上.

我怎样才能做到这一点?

谢谢,

RL

小智 8

您可能需要做的是检查手势识别器的state属性,而不是禁用它,如果状态是UIGestureRecognizerStateBegan(或UIGestureRecognizerStateEnded),则只显示下一个视图控制器.

您需要更改方法以接受手势识别器作为参数(并更新@selector参数)并检查其状态:

UILongPressGestureRecognizer *longPressTap = 
    [[UILongPressGestureRecognizer alloc] initWithTarget:self 
        action:@selector(memberListWithSearchOptions:)];  //colon at end

//...

- (void)memberListWithSearchOptions:(UILongPressGestureRecognizer *)lpt
{
    if (lpt.state == UIGestureRecognizerStateBegan)
        //or check for UIGestureRecognizerStateEnded instead
    {
        //display view controller...
    }
}
Run Code Online (Sandbox Code Playgroud)