有没有办法检测多个平移手势? [英] Is there a way to detect multiple pan gestures?

查看:108
本文介绍了有没有办法检测多个平移手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户能够同时从每个拇指平移,但我无法弄清楚如何使用uigesturerecognizer检测它。我可以同时检测到水龙头和平底锅没问题。

I want the user to be able to pan from each thumb simultaneously but I can't figure out how to detect it with uigesturerecognizer. I can detect a tap and a pan simultaneously no problem.

看来第二个平底锅将阻止第一个平底锅。

It appears that the second pan will block the first.

感谢任何帮助。

推荐答案

我通过定义shouldReceiveTouch解决了这个问题:

I solved it by defining shouldReceiveTouch like so:

-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (gestureRecognizer == singleTap) {
        return YES;
    }
    if (gestureRecognizer == pan1 && [touch locationInView:self].x > 160) {
        return YES;
    }
    if (gestureRecognizer == pan2 && [touch locationInView:self].x <= 160) {
        return YES;
    }
    return FALSE;
}

并且initWithFrame具有以下代码:

And initWithFrame has the following code:

self.userInteractionEnabled = YES;
singleTap = [[UITapGestureRecognizer alloc]
                                     initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTapsRequired = 1;
[self addGestureRecognizer:singleTap];
[singleTap release];
NSLog(@"tap: %p", singleTap);

pan1 = [[UIPanGestureRecognizer alloc]
                               initWithTarget:self action:@selector(handlePan1:)];
[self addGestureRecognizer:pan1];
NSLog(@"pan1: %p", pan1);

pan2 = [[UIPanGestureRecognizer alloc]
                                initWithTarget:self action:@selector(handlePan2:)];
[self addGestureRecognizer:pan2];

for (UIGestureRecognizer *recognizer in self.gestureRecognizers) {
    recognizer.delegate = self;
}
NSLog(@"pan2: %p", pan2);

这篇关于有没有办法检测多个平移手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆