gpt4 book ai didi

ios - 选择并拖动图 block

转载 作者:行者123 更新时间:2023-11-29 01:33:31 25 4
gpt4 key购买 nike

我正在尝试制作一款涉及点击并拖动方 block 以创建路径的游戏,类似于流行的游戏 Flow Free.

我希望能够在一次滑动中选择一个图 block 并滑动我的手指,但是我遇到了一些问题。我曾尝试使用 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 来持续检查滑动方向的变化?任何帮助,将不胜感激。提前致谢!

最佳答案

您的评估是正确的:UISwipeGestureRecognizer 对此并不是很有用,因为它仅在滑动完成后才识别

您想要的是在滑动发生时跟踪项目,您将使用 UIPanGestureRecognizer 并跟踪每个 Action 。

要跟踪哪个方向,你可以做类似这样的事情:

- (void)onPan:(UIPanGestureRecognizer *pan) {
CGPoint translation = [pan translationInView:[pan view]];
if (translation.x > 0) {
// moving right...
}

// important to "eat" the translation if you've handled the
// UI changes, otherwise the translation will keep accumulating
// across multiple calls to this method
[pan setTranslation:CGPointZero inView:[pan view]];

希望这对您有所帮助。

关于ios - 选择并拖动图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33205317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com