views:

40

answers:

3

hello all

recently i used this codes to handle drag touches :

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

but my problem when the user touches 2 buttons at the same time only one called how to fix this?

A: 

The UIGestureRecognizer is easy to implement, and less error prone about touch event handling. When second button is pressed, the press event may be entered on touchesBegan ,touchesMoved, or touchesEnded, you have to check [touches count] at these places. But if you want to handle dragging behavior, the touchesMoved is the best place to check two touches or only one touch.

As Eiko said, you should implement touchedCanceled. The sequence of touch event may be

  • touchedBegan -> touchedMoved -> touchedEnded -> touchedCanceled,
  • or touchedBegan -> touchedMoved -> touchedCanceled (no touchedEnded).

If there are no movement, then touchedMoved won't be called. It means the sequence of touch event will be

  • touchedBegan -> touchedEnded -> touchedCanceled.
  • or touchedBegan -> touchedCanceled.
Toro
A: 

thanks all for answers but in my code i used UITouch *t =[..]; it is ok if i put it in a for loop for (UITouch *t in ... ) so when the user touch 2 fingers simultaneously the method called twice

Bobj-C