我正在使用 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 正在工作,其他两个 Begin 和 Changing 都不起作用。