UIGestureRecognizer receive touch but forward it to UIControl as well
Have you tried with this?
cancelsTouchesInView A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.
@property(nonatomic) BOOL cancelsTouchesInView
mostafa tourad
Connect via Xing: https://www.xing.com/profile/Till_Toenshoff?sc_o=mxb_p Connect via LinkedIn: http://www.linkedin.com/pub/till-toenshoff/1/3aa/a48
Updated on June 03, 2022Comments
-
mostafa tourad almost 2 years
How would you allow a
UIGestureRecognizer
of aUIView
to receive a touch event but also make sure that another, underlaying/overlayingUIView
also receives that very same touch event?Lets say I have got the following view-hierachie:
Views A (blue) and B (red) are both subviews of the same superview (gray). In other words, they are both siblings and the order decides on which of them covers the other.
Option 1: View B (red) has a regular
UIButton
as its subview. Option 2: View A (blue) has a regularUIButton
as its subview.Given Option 1 for the sake of explanations: View A (blue) has a
UITapGestureRecognizer
(or maybe even more, other UIGestureRecognizers) attached. What would be the most elegant approach to make sure that theUIButton
does receive all touches on its region but also the view A (blue) receives those touches on itsUITapGestureRecognizer
?If possible by any means, the solution should not involve extending the
UIButton
-class and manually forwarding any events from the button itself. Imagine view B would contain a lot more controls and not just a button. All of those controls should somehow allow view A to receive the touches on itsUIGestureRecognizer
.I did provide two options as I do not care which of those views (A or B) comes first as long as both receive the touches.
All of my approaches so far abruptly reached dead-ends. Maybe a custom responder-chain would be a nice solution? I keep thinking that there must be an elegant solution within the entire
UIKit
/UIEvent
/UIResponder
stack. -
mostafa tourad almost 13 yearsI did try that with both, Option 1 and 2 and using that property did not make any difference; in both cases, only the button or only the view received the touches on that button-region.
-
mostafa tourad almost 13 yearsWhoops, I did actually try a different option when attempting to get cancelsTouchesInView to work. My button was a sibling of view A and B, hence the property had no effect. When using option 1 as described in my question, that property works exactly as described. Any touch onto that button triggers the button touch-up-inside as well as a touch gesture recognition on the superview of that button. That does not actually solve my entire quest (get touch recognized also onto that other view) but it gets me a big step closer to the goal - hence a +1 - ty.
-
tmr over 9 yearsexample code, in my case, '-(IBAction)handleHoldOnPlay:(UIGestureRecognizer*)sender { 'sender.cancelsTouchesInView = NO;...' (thank you sergio)