2012-05-05 75 views
3

我加入以下手勢識別的電線: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]; 
} 

這讓是我一個點即使我用兩根手指觸摸,也可以觸摸。我如何檢索第一次和第二次觸摸的電源線?

回答

8

您可以使用這些方法訪問所有的亮點:

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

它們在基類中定義,UIGestureRecognizer

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

問候, 尼爾。

相關問題