简体   繁体   English

如何在UIPangestureRecognizer上禁用多点触控?

[英]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. 我有一个UICollectionView向其中添加了UILongPressGestureRecognizerUIPangestureRecognizer以用于长按和重新排序单元格。 And also I have added UIPanGestureRecognizer for all the UICollectionViewCells to show delete and few options on the right side. 我还为所有UICollectionViewCells添加了UIPanGestureRecognizer以在UICollectionViewCells显示delete和一些选项。

My problem is when I pan two UICollectionViewCells with two fingers, both the UICollectionViewCells are detecting the pan and showing the options. 我的问题是,当我用两个手指平移两个UICollectionViewCells时,两个UICollectionViewCells都在检测平移并显示选项。 I want only one of the UICollectionViewCell to detect its UIPangestureRecognizer at a time. 我只希望其中一个UICollectionViewCell检测其UIPangestureRecognizer 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. 如果由于Gesture视图实现仍不能解决问题,则可以使用TouchedFlag保持单元上的触摸。

You can set in 您可以设置

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

You can set TouchedFlag to 1 while 您可以将TouchedFlag设置为1,同时

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

And set back while PanGesture get ended in PanGesture结束时PanGesture

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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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