UILongPressGestureRecognizer on UITableViewCell - double call

前端 未结 2 1280
情歌与酒
情歌与酒 2020-12-10 19:47

I\'m using the UILongPressGestureRecognizer in a cell. What I need is: when a user taps a cell for 1.0 seconds, call one view controller. If the user taps the cell, another

相关标签:
2条回答
  • 2020-12-10 20:30

    Instead of disabling it, what you probably need to do is check the gesture recognizer's state property and only display the next view controller if the state is UIGestureRecognizerStateBegan (or UIGestureRecognizerStateEnded).

    You'll need to change your method to accept the gesture recognizer as a parameter (and also update the @selector parameter) and check it's state:

    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...
        }
    }
    
    0 讨论(0)
  • 2020-12-10 20:34

    You have to check state as below

    -  (void)memberListWithSearchOptions:(UILongPressGestureRecognizer*)sender {
    if (sender.state == UIGestureRecognizerStateEnded) {
        NSLog(@"UIGestureRecognizerStateEnded");
        //Do Whatever You want on End of Gesture
    }
    else if (sender.state == UIGestureRecognizerStateBegan){
        NSLog(@"UIGestureRecognizerStateBegan.");
        //Do Whatever You want on Began of Gesture
    }
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题