5

私はUISwipeGestureRecognizer:を設定しました

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:delegate action:@selector(handleSwipeGesture:)];
swipe.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipe];
[swipe release];

スワイプすると、プレーヤーはスワイプの方向に移動します。ただし、スワイプした指が画面から離れるまで、プレーヤーは動き続ける必要があります。touchesEnded:メソッドを使用してみましたが、最初にスワイプしないタッチを行う必要があります。スワイプジェスチャを行ったタッチを取得するにはどうすればよいですか?そのタッチが画面から離れたことをどのように検出できますか?

4

2 に答える 2

6

この質問に対する回答にはすでに満足していると思いますが、スワイプジェスチャの代わりにUIPanGestureRecognizerを使用することをお勧めします。

パンジェスチャレコグナイザーを使用すると、ユーザーが指のドラッグを停止するまでメッセージがセレクターに繰り返し送信されます。ドラッグが停止すると、セレクターがもう一度呼び出され、のが渡されgesture.stateますUIGestureRecognizerStateEnded。例:

- (void)panGesture:(UIPanGestureRecognizer *)gesture {
    if (gesture.state == UIGestureRecognizerStateEnded) {
        CGPoint translation = [gesture translationInView:self.view];
        //This contains the total translation of the touch from when it 
        //first recognized the gesture until now.
        //
        //e.g (5, -100) would mean the touch dragged to the right 5 points, 
        //and up 100 points.
    }
}
于 2013-04-06T21:04:52.507 に答える
1

Appleのドキュメントを調べた後、UIGestureRecognizerの次のプロパティを見つけました。

@property(nonatomic) BOOL cancelsTouchesInView

NOジェスチャレコグナイザが受信するマルチタッチシーケンスの一部であるすべてのタッチを受信者のビューが処理できるように設定します。

于 2010-08-07T19:47:58.227 に答える