UIGestureRecognizer in superview firing
UIGestureRecognizer in superview firing
- Subject: UIGestureRecognizer in superview firing
- From: Roland King <email@hidden>
- Date: Mon, 02 May 2011 16:15:59 +0800
I have a UIView subclass which has a number of UIButtons and UISliders on it, it's a sort of control panel. I added UIPanGestureRecognizer to it with the idea that if you stick your finger down outside one of the embedded controls, you can move the window around. Wrote the handler for the gesture recognizer, that worked.
However I found that if I press one of the buttons, or try to drag one of the sliders which are subviews of my view, the PanGestureRecognizer fires. That completely breaks those controls as the sliders stop sliding and you cannot drag yourself off the button to cancel the press, you just drag the view around.
I've re-read the UIGestureRecognizer documentation again twice and cannot figure out why this is happening. Take the example of a touch going down on the knob of one of the sliders, hitTest:withEvent correctly returns the UISlider (I tested that) and so the touches should go to the slider directly and not to its superview, my UIView subclass or its attached gesture recognizer at all. I understand that gesture recognizers get touches before their attached views, this from the Event Handling Guide For iOS
" Delivery of events initially follows the usual path: from operating system to the application object to the window object representing the window in which the touches are occurring. But before sending an event to the hit-tested view, the window object sends it to the gesture recognizer attached to that view or to any of that view’s subviews."
In this case the hit-tested view was the UISlider so I would expect touches to be sent to any gesture recognizers on that UISlider and its subviews and then to the UISlider itself but not to the UIView of which it's a subview nor its attached gesture recognizer, the slider would work, the view wouldn't try to pan.
I did wonder if the UISlider didn't (for some strange reason) respond to touchesBegan:withEvent: and thus the touch was bubbling back up to the superview, my class, and being sent to the gesture recognizer there at the same time, but apart from there being no documentation about such a flow, the UISlider DOES respond to touchesBegan:withEvent:, so thats not it.
I can only find documentation which talks about subviews of the hit-tested view and their recognizers receiving touches, nothing can I find about superviews, so this flow is puzzling.
I'm going to use the PanGestureRecognizer delegate method gestureRecognizer:shouldReceiveTouch: to stop this happening. Can someone however explain which piece of documentation I've not read or have misunderstood which explains why the PanGR on the superview of the hit-tested view is getting touches at all?
Thanks
Roland
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden