gpt4 book ai didi

iphone - 是否可以同时使用 UIPanGesture 和 UISwipeGesture?

转载 作者:行者123 更新时间:2023-12-03 20:52:32 25 4
gpt4 key购买 nike

我有一个 UIIMageView 子类,并且添加了 UIPanGestureRecognizer 和 UISwipeGestureRecognizer,如下所示:

self.userInteractionEnabled = YES;

UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[self addGestureRecognizer:panGesture];

UISwipeGestureRecognizer * swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeUp:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self addGestureRecognizer:swipeUp];

UISwipeGestureRecognizer * swipeDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeDown:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self addGestureRecognizer:swipeDown];

但是当我向上或向下滑动时,我的选择器不会被调用,但平移总是会被调用。

任何澄清都会有帮助。

谢谢

最佳答案

问题是滑动手势也会被识别为 panGesture。

您需要做的是将委托(delegate)设置为实现该方法的类:

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

这将允许您同时识别两个手势,但需要清楚的是,当您的滑动被调用时,您的平移也会被调用。

From apple documentation :

This method is called when recognition of a gesture by either gestureRecognizer or otherGestureRecognizer would block the other gesture recognizer from recognizing its gesture. Note that returning YES is guaranteed to allow simultaneous recognition; returning NO, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer's delegate may return YES.

关于iphone - 是否可以同时使用 UIPanGesture 和 UISwipeGesture?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9907673/

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