On Mon, 02 May 2011 16:15:59 +0800, Roland King <r...@rols.org> said:
>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.

This is correct behavior and is very thoroughly explained in my book (Chapter 
18, "Touches"). As I say there, you need to think of a view as surrounded by a 
swarm of gesture recognizers - those attached to the view, those attached to 
its superview, and so on up the chain. Every gesture recognizer in the swarm 
gets a crack at recognizing any gesture; if any does, then (by default) all the 
other gesture recognizers in the swarm are made to fail.

The reason for this behavior is obvious if you consider the case of two views 
where you put one finger on each view and rotate around their common center. 
Neither view can detect this gesture, since it is a two-finger gesture and each 
view knows about only one finger, so the only way this can work is to attach 
the rotate gesture recognizer to the superview. This in turn implies that 
touches must be delivered to gesture recognizers up the superview chain.

>I'm going to use the PanGestureRecognizer delegate method 
>gestureRecognizer:shouldReceiveTouch: to stop this happening.

That's correct. It's very easy to implement this, because a touch has a view, 
so you can detect immediately that this touch was not on the superview. m.

--
matt neuburg, phd = m...@tidbits.com, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to