views:

888

answers:

2

I have been over the iPhone Programming Guide several times regarding the behavior of when the event methods are called in an app.

From what the guide says: touchesBegan is called when a finger first touches the screen.

touchesMoved is called when a finger on the screen moves.

touchesEnded is called when a finger lifts off the screen.

The issue becomes a little clouded with multiple fingers are involved:

Even with the Multi-touch Interaction flag set to NO, the app continues to call the touchesBegan method of a view that is currently tracking another touch. This seems counter intuitive to me.

Is this the correct behavior? I would think that a new UITouch (even added to the current event being tracked) would not trigger the touchesBegan method.

Of note, I set this flag in IB as well as programatically to make sure I wasn't missing something.

Thanks, Corey

A: 

Yes I believe it is correct behavior. You can track the location of each touch event so I think you just need to structure your logic such that you handle:

UITouch *touch = [[allTouches allObjects] objectAtIndex:0];

to get the first touch, and objectAtIndex:1 for the second. I think it goes up to four or five (not sure, please see the docs).

Good luck!

Genericrich
A: 

I figured out my problem, but first to clarify proper functionality of multiple touches:

If your view's multipleTouchEnabled flag is set to NO, the touchesBegan method of that view should NOT fire if a second touch is applied to a screen.

With that, the solution to my problem:

My view contains several subviews. The view is responsible for handling touches for itself AND the subviews.

When my code was not functioning properly, I had the subview's userInteractionEnabled = YES. This meant that when a subview was touched, it would forward the touch to the superview, REGARDLESS of whether the superview was tracking another touch.

In other words, although UIApplication respects the multiTouchEnabled flag of a view, other views in the responder chain do not.

Corey Floyd