Reputation: 5426
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?
Upvotes: 0
Views: 208
Reputation: 5426
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
Upvotes: 0
Reputation: 18428
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
If there are no movement, then touchedMoved won't be called. It means the sequence of touch event will be
Upvotes: 0
Reputation: 203
You should consider UIGestureRecognizer if it's simply a drag gesture http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer
Upvotes: 1