Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel a sequence of UITouch events?

Tags:

I have a UIImage view that responds to touch events. I want to cancel the touch sequence, i.e., further calls to touchesMoved:, if the touch goes outside of certain bounds. How can I do that?

I know that in touchesMoved: I can inspect the coordinates of the touch object and ignore it, but what I don't know is how to cancel the sequence altogether. I don't see any method documented in the Apple Developer UIResponder Reference that I can call to cancel a touch sequence.

like image 376
subjective-c Avatar asked Feb 10 '09 18:02

subjective-c


2 Answers

This solution may be a bit kludgy, but you could implement and manually call

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

I am basing this solution loosely on some tweaking I did to the MoveMe sample app on Apple's iPhone sample code site where I modified the touchesMoved method to look like this:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
     UITouch *touch = [touches anyObject];
     if ([touch view] == placardView)
         CGPoint location = [touch locationInView:self];
         placardView.center = location;
         // I added the following line:
         [self touchesCancelled:touches withEvent:event];
         return;
}
like image 109
Michael Fey Avatar answered Sep 24 '22 22:09

Michael Fey


Try temporary setting the UIImageView's userInteractionEnabled property to NO

like image 22
Zaky German Avatar answered Sep 23 '22 22:09

Zaky German