gestureRecognizer: shouldReceiveTouch: not getting

2020-08-15 04:54发布

问题:

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

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

回答1:

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.

touchHold.delegate = self;

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

@interface YourViewController <UIGestureRecognizerDelegate>