Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why in shouldReceiveTouch does my gesture recognizer always report being tapped in the same location?

I have the following code:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {
    NSLog(@"%@", NSStringFromCGPoint([recognizer locationInView:self.view]));
    ...

Every time I tap, however, I get {0, -64}. No matter where I tap. What am I doing wrong?

like image 662
Doug Smith Avatar asked Feb 15 '23 18:02

Doug Smith


1 Answers

I think this is the expected behavior because, "This method is called before touchesBegan:withEvent: is called on the gesture recognizer for a new touch". So, I think this means the recognizer won't know about its location yet. To get the location, use the touch argument provided instead:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {
    NSLog(@"%@", NSStringFromCGPoint([touch locationInView:self.view]));
    ...
like image 196
rdelmar Avatar answered Apr 29 '23 03:04

rdelmar