gpt4 book ai didi

iphone - 同时使用触摸和触摸手势识别器

转载 作者:可可西里 更新时间:2023-11-01 05:30:10 25 4
gpt4 key购买 nike

我在我的 UIView 上使用了两个手势识别器。一个是标准的 UITapGestureRecognizer,另一个是我写的非常简单的触摸识别器:

@implementation TouchDownGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (self.state == UIGestureRecognizerStatePossible) {
self.state = UIGestureRecognizerStateRecognized;
}
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
self.state = UIGestureRecognizerStateFailed;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.state = UIGestureRecognizerStateFailed;
}

@end

只有当我为它们分配一个包含此方法的委托(delegate)时,它们才能一起工作:

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

一切正常,但当我长按该 View 时,触摸识别器会触发,而触摸识别器不会。短按一切正常,它们都会开火。

我在 UIGestureRecognizerDelegate 中实现了所有方法以返回 YES 无济于事。如果我添加日志记录以查看与委托(delegate)和我自己的识别器内部的交互,我可以看到对于短按和长按,调用序列是相同的 — 除了调用 touch up 识别器。我做错了什么?

最佳答案

为什么不直接从 UILongPressGestureRecognizer 检查 touchUp?

-(void)selectionDetected:(UILongPressGestureRecognizer*)longPress
{
if(longPress.state==1)
{
//long Press is being held down
}
else if(longPress.state==3)
{
//the touch has been picked up
}
}

关于iphone - 同时使用触摸和触摸手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18065047/

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