3

我希望用户能够同时从每个拇指上平移,但我不知道如何使用 uigesturerecognizer 来检测它。我可以同时检测水龙头和平底锅没问题。

看来第二个平底锅会挡住第一个平底锅。

任何帮助表示赞赏。

4

1 回答 1

2

我通过定义 shouldReceiveTouch 来解决它,如下所示:

-(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 具有以下代码:

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);
于 2012-09-15T03:33:03.457 回答