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.
I achieve this by removing the view from its superview and adding it straight back.
This breaks the responder chain to the view so any remaining touches will not be received on the view. The next touch will still be received as normal.
You can check that, the touch point locations are in CGRect (ie. points are in Rectangle of your imageview) or not. If they are not in that Rect, the touch will be cancelled.
On iOS5 there seems to be a private method in UITouch
Depending on apple's implementation it could stop sending events
Another way of doing so would be using associative objects
I've faced the same problem recently and found a standard way to solve it. You can use [[UIApplication sharedApplication] beginIgnoringInteractionEvents] to stop delivering touchesMoved events to your whole app. Make sure to enable them using [[UIApplication sharedApplication] endIgnoringInteractionEvents] when you need to receive touches again.
I don't think it's possible because I don't see it documented and none of these solutions work.
You need to call
[super touchesMoved:withEvent:]
in order to let the super view clean up from the event but more importantly, you need to not call[super touchesCancelled:withEvent:]
.Here's what I used on a cell to keep it from getting selected when I detected a swipe: