Alex Rivera | Logout

Can you force a touch event to cancel after touchesBegan?

Asked 2009-07-23T06:37:10.830
10

Given a certain state of one of my UIViews I'd like it to respond to touchesBegan and then cancel any further touchesMoved/Ended that continue from that particular touchesBegan event.

Basically I have an UIView subclass at rest and if it's touched I'd like to move some other UIViews out of the way... then the next time it's touched the responder chain can respond normally to touchesMoved/Ended...

yes, i could check for this state in touchesMoved/Ended but I'm wondering if there's a way to just derail that touch event mid-phase.

Edit
Report

1 Answer

0

Assuming you have one touch, the touch object is always the same, meaning that you can compare using ==

UITouch *anyTouch = [touches anyObject];
if (anyTouch != self.lastTouch)
     return;

So, by storing the last UITouch in your UIView subclass (in the example I use a property called lastTouch), you can figure out which touches you want to ignore and which you want to recognize on your moved and ended/cancelled. Not elegant and not that direct, but it lets you get at what you want.

This can be expanded for multiple touches, of course.

answered 2011-12-23T14:07:22.287

Your Answer