3

我添加了以下手势识别器:

UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc] 
                              initWithTarget:self 
                              action:@selector(ViewDragging2:)];
[d2 setMinimumNumberOfTouches:2];
[d2 setMaximumNumberOfTouches:2];
[targetView addGestureRecognizer:d2];

发生该事件时触发的方法是:

-(void)ViewDragging2:(UIPanGestureRecognizer*)sender {

    // some point
    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:targetView];
}

即使我用两根手指触摸,这也让我一触即发。如何找回第一次和第二次触摸的绳索?

4

2 回答 2

8

您可以使用以下方法访问所有触摸:

  • (NSUInteger)numberOfTouches
  • (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view

它们在基类UIGestureRecognizer中定义。

于 2012-05-05T04:53:01.557 回答
4

试试下面的代码。

UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc] 
                          initWithTarget:self 
                          action:@selector(ViewDragging2:)];
  [d2 setMinimumNumberOfTouches:2];
  [d2 setMaximumNumberOfTouches:2];
 [targetView addGestureRecognizer:d2];

发生该事件时触发的方法是:

   -(void)ViewDragging2:(UIPanGestureRecognizer*)sender
    {
      // where touchIndex is either 0 or 1.
       CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
   }

检查此链接 locationOfTouch 和 numberOfTouches

问候,尼尔。

于 2012-05-05T05:26:25.407 回答