xcode 手势识别器:shouldReceiveTouch:没有被调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12869541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:48:43  来源:igfitidea点击:

gestureRecognizer: shouldReceiveTouch: not getting called

iphoneobjective-cxcode

提问by iamruskie

gestureRecognizer:shouldReceiveTouch: method isnt being called. Have i set it up improperly?

gestureRecognizer:shouldReceiveTouch: 方法未被调用。我是否设置不当?

-(id) init 
{
UILongPressGestureRecognizer *touchHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouchHold:)];
touchHold.minimumPressDuration = 1.0f;
touchHold.numberOfTouchesRequired = 1;
[[CCDirector sharedDirector].openGLView addGestureRecognizer:touchHold];
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{
     return NO;
}

Press and hold method is still being called even though i set the bool to no.

即使我将 bool 设置为 no,仍会调用按住方法。

回答by ewiinnnnn

Seems like you haven't set the delegate ?

好像你还没有设置委托?

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

Is the part of UIGestureRecognizerDelegate. So you should have set the delegate too.

是 UIGestureRecognizerDelegate 的一部分。所以你也应该设置委托。

touchHold.delegate = self;

Edit: You should tell your view controller to implement the UIGestureRecognizerDelegate. Something like

编辑:您应该告诉您的视图控制器实现 UIGestureRecognizerDelegate。就像是

@interface YourViewController <UIGestureRecognizerDelegate>