Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 同时使用触碰和触碰手势识别器_Iphone_Ios_Uikit_Uigesturerecognizer - Fatal编程技术网

Iphone 同时使用触碰和触碰手势识别器

Iphone 同时使用触碰和触碰手势识别器,iphone,ios,uikit,uigesturerecognizer,Iphone,Ios,Uikit,Uigesturerecognizer,我在我的UIView上使用了两个手势识别器。一个是标准的uitappesturerecognizer,另一个是我写的非常简单的触地识别器: @implementation TouchDownGestureRecognizer - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (self.state == UIGestureRecognizerStatePossible) { sel

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

@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
只有当我为它们两个都指定了一个包含此方法的委托时,它们才能一起工作:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}
这一切都很好,但当我在该视图上执行长按时,触控识别器启动,触控识别器不启动。总之,一切都很好,他们都开火了


我在
UIgestureRecognitizerDelegate
中实现了所有方法,以返回YES但无效。如果我添加日志记录以查看与委托的交互以及在我自己的识别器中的交互,我可以看到,对于短点击和长点击,调用序列都是相同的——除了对修饰识别器的调用。我做错了什么?

为什么不直接从
UILongPressGestureRecognitor
检查修补

-(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
    }
}

非常好的建议,谢谢!该识别器需要将
minimumPressDuration
设置为0,现在可以正常工作没有问题,乐意帮助!