How to find out if UITapGestureRecognizer has been added to subview

I add subviews programmatically. for each spy I add a gesture repeater:

UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake((position*1024)+200,0,image.size.width,image.size.height); UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleFingerTap:)]; singleFingerTap.numberOfTapsRequired = 1; [imageView addGestureRecognizer:singleFingerTap]; [singleFingerTap release]; 

but the answer does not answer, how can I confirm that the gesture has been added to the view?

+4
source share
1 answer

Add this after the code:

 NSLog(@"imageView.gestureRecognizers: %@", [imageView.gestureRecognizers description]); 

If you correctly added gestureRecognizers, it will print a description of each of them on the console. If not, the console will display (NULL) or an empty array.


You can also set the gesture recognizer delegate:

 [singleFingerTap setDelegate:self]; 

Then add a delegate method and set a breakpoint to make sure it is called:

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { NSLog(@"gestureRecognizerShouldBegin: called"); return YES; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { NSLog(@"shouldReceiveTouch: called"); return YES; } 
+3
source

Source: https://habr.com/ru/post/1435583/


All Articles