[英]SwipeGesture in Iphone Cocos2d
I am using UISwipeGestureRecognizer to get swipe gesture in iPhone. 我正在使用UISwipeGestureRecognizer来获取iPhone中的滑动手势。 i want to get 2 location points on Began of swipe touch and on end of swipe touch.
我想在滑动触摸开始时和滑动触摸结束时获得2个位置点。 i have implemented swipe touch method as below
我已实现如下滑动触摸方法
- (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));
}
//}
}
My swipe touch is working. 我的滑动触摸正常。 but it only shows UIGestureRecognizerStateEnded.
但它仅显示UIGestureRecognizerStateEnded。 even when i swipe on screen and my touch is not ended yet but the StateEnded is called.
即使我在屏幕上滑动并且触摸还没有结束,但仍调用StateEnded。 how can i call StateBegin and get location and then StateEnd.
我怎样才能打电话给StateBegin并获取位置,然后再给StateEnd。 right now just StateEnded is working other two Begin and Changing are not working.
现在,只有StateEnded在起作用,另外两个Begin和Changes都不起作用。
Update: I find the reason: 更新:我找到原因:
A swipe is a discrete gesture, and thus the associated action message is sent only once per gesture.
滑动是离散手势,因此每个手势仅发送一次相关的动作消息。
And this image: 这张图片:
So there are only three states for UISwipeGestureRecognizer
:possible, recognized and ended. 因此,
UISwipeGestureRecognizer
只有三种状态:可能,已识别和已结束。 But I still don't know why possible is not called. 但是我仍然不知道为什么不叫可能。
I tried your code and get the same result. 我尝试了您的代码,并得到相同的结果。 I also don't know why this happen.
我也不知道为什么会这样。 If you can't find solution for this problem I suggest you use the for touch methods to analysis the touch yourself.
如果找不到解决此问题的方法,建议您使用for touch方法自己分析触摸。 This can surely handle the event but a little complicated than use gesture recognizer.
这肯定可以处理事件,但是比使用手势识别器要复杂一些。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.