2012-05-05 5 views
3

に触れる:UIPanGestureRecognizerは、すべてのコードを取得する私は、次のジェスチャー認識追加した

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

をし、そのイベントが発生したときのがクビ方法は次のとおりです。

私に1点をだ取得
-(void)ViewDragging2:(UIPanGestureRecognizer*)sender { 

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

私は2本の指で触れても触れる。どのようにして1番目と2番目の接触のコードを取り出すことができますか?

答えて

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

よろしく、 ニール。

関連する問題