UIScrollView and tap gesture sweep detection

I added TapGestureRecognizer for my self.view:

tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)]; tap.numberOfTapsRequired = 1; tap.numberOfTouchesRequired = 1; [self.view addGestureRecognizer:tap]; [tap release]; 

The view contains one UIScrollView with images and shortcuts. I want to determine if the user is deleting a shortcut or not.

 - (void)singleTap:(UIGestureRecognizer*)gestureRecognizer { CGPoint pt = [gestureRecognizer locationInView:self.view]; UIView *v = [self.view hitTest:pt withEvent:nil]; if ([v isKindOfClass:[UILabel class]]) { NSLog(@"label!"); return; } // else do other stuff if its not a label 

However, I do not see the shortcut! in my journal.

+4
source share
2 answers

I think because userInteractionEnabled defaults to NO on UILabel s. Try turning it on.

EDIT: That was really a hunch, but just for confirmation, Apple documents in the [UIView hitTest:withEvent:] state:

This method ignores hidden viewers that have disabled user interaction or have an alpha level of less than 0.01.

+5
source

Your subzones, such as the shortcuts themselves, actually hide the user's interaction with the base view.

Why don't you add gesture recognizers to your tags. Alternatively, you can use UIButton for shortcuts.

Or -

if you do not want to determine which label has been affected, you can add an invisible view (empty view, no hidden view, not one with alpha = 0) on top of all labels and add theme gesture recognizers.

0
source

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


All Articles