【发布时间】:2015-10-19 01:36:58
【问题描述】:
我正在尝试制作一款涉及点击和拖动图块以创建路径的游戏,类似于流行游戏Flow Free.
我希望能够在一次滑动中选择一个图块并滑动我的手指,但是我遇到了一些问题。 我曾尝试使用 SwipeGestures,在那个
// listen for swipes to the left
UISwipeGestureRecognizer * swipeLeft= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeLeft];
// listen for swipes to the right
UISwipeGestureRecognizer * swipeRight= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeRight];
// listen for swipes up
UISwipeGestureRecognizer * swipeUp= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeUp)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeUp];
// listen for swipes down
UISwipeGestureRecognizer * swipeDown= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeDown];
我的问题是 SwipeGestures 只识别每次屏幕按下的滑动——如果我改变方向,中间滑动,它不会注册。
假设我需要使用 UIGestureRecognizers,我是否可以使用 PanGestureRecognizer 和 SwipeGestureRecognizer 来不断检查滑动方向的变化? 任何帮助,将不胜感激。提前致谢!
【问题讨论】:
-
这是因为您为每个滑动方向传递了不同的方法,而不是让 UIPanGestureRecognizer 检测滑动方向。
标签: ios objective-c