`I've got view with a UIImageView as a subview. The main view has a single tap GestureRecognizer on it that works 99% of the time.
Every once in a while, the gesture recognizer seems to fail, and the event gets pushed up the stack to the next responder. I've added a breakpoint in the hitTest method of that top view, and the hit test method correctly returns the inner-most UIImageView in all cases, including when the event goes to the wrong place.
In what situation could a view be the result of a hitTest but not get the event passed to its gesture recognizer? I've printed out this debug code from the hitTest breakpoint when the gesture selector doesn't get called:
(lldb) po u
$2 = 0x20854520 <UIImageView: 0x20854520; frame = (0 0; 61 62); opaque = NO; layer = <CALayer: 0x208e7670>>
(lldb) po [u superview]
$0 = 0x1fd225e0 <HotspotView: 0x1fd225e0; frame = (303 663; 61 62); gestureRecognizers = <NSArray: 0x2082b850>; layer = <CALayer: 0x1fd15af0>>
(lldb) po ((HotspotView *)u.superview).gestureRecognizers
$1 = 0x208bc940 <__NSArrayI 0x208bc940>(
<UITapGestureRecognizer: 0x20828fa0; state = Possible; cancelsTouchesInView = NO; delaysTouchesEnded = NO; view = <HotspotView 0x1fd225e0>; target= <(action=handleSingleTap:, target=<HotspotView 0x1fd225e0>)>>
)
u
is the result of the hit test (the UIImageView). u.superview
is the container view that has the gesture recognizer attached to it. So, here, I confirm that u.superview
has a gesture recognizer. Shouldn't it, then, receive that event? In what situation would this event not make it into singleTap and instead bubble up to the next responder?
edit: I've managed to capture the problem again (XCode crashed last time I had it after a few minutes...) and now I've found that the touch even makes it all the way into the HotspotView. touchesBegan gets the touch correctly even if it then fails to call the gesture recognizer. I've logged the touch and touch events for both successful and unsuccessful taps (in terms of whether they call the GR or not) and they appear to be identical.
So, now I'm even more lost.
1) The right object is returned for the hit test
2) The right object receives its touchesBegan call
3) The object has its gesture recognizer
4) And yet, sometimes, that gesture recognizer is not called (with no reliability and very difficult reproduction).
userInteractionEnabled
of the image view? I presume you did, since it is the result of a hit test. – matt