且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测UIGestureRecognizer何时向上,向下,向左和向右Cocos2d

更新时间:2022-12-05 17:07:41

显然,每个UISwipeGestureRecognizer只能检测指定方向的滑动。即使方向标志可以在一起ORIS,UISwipeGestureRecognizer忽略额外的标志。



解决方案是添加一个UISwipeGestureRecognizer您要滑动手势的每个方向识别,并且将每个识别器的方向相应地设置为上,下,左和右。如果你想测试任何方向的滑动,你必须添加四个UISwipeGestureRecognizer。



这是奇怪的,但这是唯一的方式为我工作。 / p>

I have a CCSprite that I want to move around using gestures. Problem is I'm completely new to Cocos2D. I want my sprite to perform one action when the gesture is up, another one when gesture is down, another action when gesture is right and same thing for left. Can someone point me in the right direction?

Thanks!

Apparently each UISwipeGestureRecognizer can only detect the swipe in the given direction. Even though the direction flags could be OR'ed together the UISwipeGestureRecognizer ignores the additional flags.

The solution is to add one UISwipeGestureRecognizer for each direction you want the swipe gesture to be recognized, and set each recognizer's direction accordingly to either up, down, left and right. If you want to test for a swipe in any direction you'll have to add four UISwipeGestureRecognizers.

It's kind of odd but that's the only way it worked for me.