UIPanGestureRecognizer获取所有触摸的线索

时间:2012-05-05 03:33:13

标签: iphone objective-c uipangesturerecognizer

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

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];
}
即使我用两根手指触摸,这也让我感觉很轻松。如何检索第一次和第二次触摸的线?

2 个答案:

答案 0 :(得分:8)

您可以使用以下方法访问所有内容:

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

它们在基类UIGestureRecognizer中定义。

答案 1 :(得分: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 and numberOfTouches

此致 尼尔。