I have a subclass of UIView
on top of a UITableView
. I am using the UITableView
to display some data and, at the same time, I would like to overlay an animation that follows the finger (for instance, leaving a trail).
If I get it right, I need the touch events to be handled both by the UIView
subclass and the UITableView
. How can I do that?
Is it possible to have, ie, touchesMoved
being triggered on the UIView subclass and then on UITableView
?
Thank you so much for any help.
UITableView relays unhandled touch events to UIView. (Google "responder chain") UITableView Documentation
So, you can handle your touch events in UIView only. So. In your UIView
touchesstart - do initialization stuff
touchesmove - draw tail on UIView (Use timers/delayedresponse to desable points so that it would look like a trail)
touchesend - do remaining stuff
Hope this helps.
No, you cann't do it implicity. Event Delivery chapter says
So, when window finds touched view it returns YES. Only one view can handle touches at the current moment.
But if you need to handle event for UITableView then handle it for UIView! You can convert touched point to required coordinates with – convertPoint, – convertRect functions, add subview to UITableView and move it depends on coordinate, and a lot of another things.
The way I have solved this problem is in a way that is not that clean, but it works. Please let me know if there's a better way to do this.
I have overridden
hitTest
for my customUIView
so that it directs touches to theUITableView
underneath. Then in theUITableView
I am handling the gestures throughtouchesBegan
,touchesMoved
, etc. There I am also callingtouchesBegan
on theUIView
.In this way touches are handled by two views. The reason why I am not doing the other way around (having
UIView
'stouchesBegan
callingUITableView
'stouchesBegan
) is that gestures recognizers on theUITableView
would not work.UIView
subclass'hitTest
UITableView
subclass'stouchesBegan