UISwipeGestureRecognizerを使用してiPhoneでスワイプジェスチャを取得しています。スワイプタッチの開始時とスワイプタッチの終了時に2つのロケーションポイントを取得したい。以下のようにスワイプタッチ方式を実装しました
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
CGPoint touchLocation = [recognizer locationInView:recognizer.view];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
CCLOG(@"Hello %@ - %d",NSStringFromCGPoint(touchLocation),recognizer.state);
if (recognizer.state == UIGestureRecognizerStateBegan) {
CGPoint touchLocation = [recognizer locationInView:recognizer.view];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
CCLOG(@"UIGestureRecognizerStateBegan %@",NSStringFromCGPoint(touchLocation));
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
CCLOG(@"UIGestureRecognizerStateChanged");
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint touchLocationEnd = [recognizer locationInView:recognizer.view];
touchLocationEnd = [[CCDirector sharedDirector] convertToGL:touchLocationEnd];
touchLocationEnd = [self convertToNodeSpace:touchLocationEnd];
CCLOG(@"UIGestureRecognizerStateEnded %@",NSStringFromCGPoint(touchLocationEnd));
}
//}
}
スワイプタッチが機能しています。ただし、UIGestureRecognizerStateEndedのみが表示されます。画面をスワイプしてタッチがまだ終了していないのに、StateEndedが呼び出された場合でも。StateBeginを呼び出して、場所を取得してからStateEndを取得するにはどうすればよいですか。現在、StateEndedだけが機能しており、他の2つのBeginとChangingは機能していません。