简体   繁体   中英

How to disable multi touch on UIPangestureRecognizer?

I have a UICollectionView to which I have added UILongPressGestureRecognizer and UIPangestureRecognizer for long press and reordering cells. And also I have added UIPanGestureRecognizer for all the UICollectionViewCells to show delete and few options on the right side.

My problem is when I pan two UICollectionViewCells with two fingers, both the UICollectionViewCells are detecting the pan and showing the options. I want only one of the UICollectionViewCell to detect its UIPangestureRecognizer at a time. Is there any solution?.

Can anyone please help me out on this?. Thanks in advance.

You can disable multi touch on collection it self. by making simple property.

[UICollectionView setMultipleTouchEnabled:NO];

If still problem is not being solve due to Gesture view implementation then you can use TouchedFlag for maintain touch on cell.

You can set in

- (IBAction) panGesture:(UIPanGestureRecognizer *)gesture;

You can set TouchedFlag to 1 while

if (gesture.state == UIGestureRecognizerStateBegan)
{
     TouchedFlag=1;
}

And set back while PanGesture get ended in

if (gesture.state == UIGestureRecognizerStateEnded)
{
     TouchedFlag=0;
}

So your finale code should look like

- (IBAction) panGesture:(UIPanGestureRecognizer *)gesture
{

    if (gesture.state == UIGestureRecognizerStateBegan && TouchedFlag==0)
    {
        TouchedFlag=1;
        //Do your PAN openration
    }
    else if (gesture.state == UIGestureRecognizerStateBegan && TouchedFlag==1) {
        //just prompt msg to user then single view at a time allowd to PAN
    }
    else if (gesture.state == UIGestureRecognizerStateEnded) {
        TouchedFlag=0;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM