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.
Try temporary setting the UIImageView's userInteractionEnabled property to NO
This solution may be a bit kludgy, but you could implement and manually call
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:"Brute force" solution depending if it suits your needs: Remove and re-initialize the subview that receives the touches or responds to them (of course take care of frame and content).
I was just trying to solve something like this, and found that none of the solutions listed her worked for me. The best i could manage was temporarily ignoring the touches, but then they resumed when the touch re-entered the view.
Finally solved it.
I guess this will work for you unless you have a specific reason for literally needing the touch sequence cancelled.
This code will help you. I disable touch event in
touchesMoved:
method and I am enabling touch event intouchesCancelled:
methodYou may create category to UITouch. You can to declare
And when you change touch.view to nil, for example, you can simulate end of dispatching touch events