Search code examples
iosuitableviewuiswipegesturerecognizer

Fire an event as soon as user places a finger on screen


I have a tableview on which each cell is having UIPanGestureRecognizer on it to have a swipe effect. But my problem is user can swipe two cells simultaneously which I want to disable.

So how to make sure that if user has his one finger on screen there shouldn't be any other gesture as long as that finger remains on screen.

I am able to disable the tableview if user swipes one cell and tries to swipe another cell . but it is not working if two cells are swiped simultaneously.


Solution

  • Well this is how I managed to resolve this issue.

    - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer
    

    {

    CGPoint velocity = [panGestureRecognizer velocityInView:(CardCellView *)panGestureRecognizer.view];
    
    if(fabs(velocity.x) > fabs(velocity.y))
    {
        tblSearchResults.userInteractionEnabled = NO;
    
        if(isActionInProgress)
            return  FALSE;
        else
            isActionInProgress = TRUE;
    }
    
    return fabs(velocity.x) > fabs(velocity.y);
    

    }

    if user swipes any cell I change BOOL isActionInProgress to true and only make it false if swiped cell is back to its original state.