touchesBegan and UIGestureRecognizer


#1

I’m a bit confused about the figure 20.2. The book says

so my interpretation is, if this gesture is recognized, then the action will be called, and UIResponder message like touchesBegan:withEvent: won’t be called.

I implemented the tap: method with the NSLog only, I also added another NSLog to method touchesBegin:withEvent:

and when I run the application, touchesBegin:withEvent: get called first, then the tap: method, and we need to remove all objects in lineInProcess to get rid of the dot.

If the gesture recognizer intercepts the touches, shouldn’t touchesBegan:withEvent: won’t get called?


#2

I did a little experiment and seems like the result I got contradicts what the book says.

I read the curious section, and it mentioned:

so basically it says when we add a gesture recognizer to a view, any touch event (ie. touchBegan, touchMoved) will either be delayed, or won’t be called. (please tell me if I have interpreted the above paragraph in the wrong way :slight_smile: ) UNLESS you manually call setDelaysTouchBegin to NO, to change the behaviour.

Now back to my experiment,in the touchBegan method I have put a trace so that I know if this method gets called or not. When I run the program, I tab on the line, or I long pressed the line, the touchBegan DID get called.

I then stopped the app, traced the delaysTouchesBegin for the tap recognizer and long pressed recognizer, and I got a NO for both recognizers. Which means, the gesture recognizers are not “greedy” by default, not until I manually set the “setDelaysTouchesBegan” to YES.


#3

Thank you.

PS: From the API doc:

[quote]@property(nonatomic) BOOL delaysTouchesBegan

Discussion
When the value of this property is NO (the default), views analyze touch events in UITouchPhaseBegan and UITouchPhaseMoved in parallel with the receiver.[/quote]