Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a 'tap' to UIButton that is underneath UIView with UISwipeGestureRecognizer?

I have a UIButton underneath a (transparent) UIView. The UIView above has a UISwipeGestureRecognizer added to it, and that is its only purpose - to detect certain swipe gestures. I want all other touches to be ignored by that UIView, and passed to other views (such as my UIButton underneath). Currently, the UIView above seems to be detecting the tap (for example), doing nothing (as it should be), and not letting the UIButton underneath get a chance to respond.

I would prefer not to implement my own swipe recognizer, if possible. Any solutions / advice? I basically just want to know how to tell a UIView to pay attention to only a certain type of added gesture recognizer, and ignore (and thus let through to views behind) all other touches.

like image 593
danbretl Avatar asked Aug 29 '11 22:08

danbretl


1 Answers

Have you set:

mySwipeGesture.cancelsTouchesInView = NO;

to allow the touches to be sent to the view hierarchy as well as the gesture?

Additionally, ensure that the view on top is:

theTransparentView.opaque = NO;
theTransparentView.userInteractionEnabled = YES;

I've had pretty good success attaching gestures to the parent view without needing to create a transparent subview on top for the gesture. Are you sure you need to do that?

like image 138
Matt Connolly Avatar answered Oct 26 '22 03:10

Matt Connolly