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;
}
即使我将bool设置为no,仍然会调用按住方法。
答案 0 :(得分:27)
好像你还没设置代表?
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
是UIGestureRecognizerDelegate的一部分。所以你也应该设置代理。
touchHold.delegate = self;
编辑: 您应该告诉视图控制器实现UIGestureRecognizerDelegate。像
这样的东西@interface YourViewController <UIGestureRecognizerDelegate>