I have a UIScrollView
to which I added a single tap gesture recognizer to show/hide some UI overlay using:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[scrollView addGestureRecognizer:singleTap];
and:
- (void)handleTap:(UITapGestureRecognizer *)sender {
// report click to UI changer
}
I added an easy table view to the bottom of the UIScrollView
. Everything works right (scrolling both horizontally and vertically) but the problem is that taps are recognized only by the gesture recognizer (above), but not by the easy table view.
If I remove The line that registers the gesture listener, everything works fine, the table view notices taps on itself.
It's as if the gesture recognizer function "eats" the tap events on the table view and doesn't propagate them downward.
Any help is appreciated
This should solve your problem.
Detect touch event on UIScrollView AND on UIView's components [which is placed inside UIScrollView]
The idea is to tell the gesture recognizer to not swallow up the touch events. To do this you need to set singleTap's cancelsTouchesInView
property to NO
, which is YES
by default.
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap];
Swift 3.0
let singleTap = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
singleTap.cancelsTouchesInView = false
singleTap.numberOfTapsRequired = 1
scrollView.addGestureRecognizer(singleTap)
And the selector method be like.
@objc func handleTap(_ recognizer: UITapGestureRecognizer) {
// Perform operation
}
I think the reason is that User Interaction Enabled
is set to false
for UIImageView. You should set it to true to enable tapping in it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With