I just don't understand what apple means by the touches canceled event and how is it called.
views:
182answers:
2Take a look at the UIResponder class - it defines all the various touch-related methods.
Basically, you have two concepts: that of a touch method, and that of a touch event. The former is encapsulated within UIResponder as different methods that are automatically called by the OS when a touch event occurs; that event, an instance of UIEvent *
, is then passed to the touch method.
Specifically, take a look at the signature for touchesEnded:withEvent:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
In this signature, you can see the name of the method (touchesEnded
, in part), the set of touches that happened, and the event (called, appropriately, event
). In your implementation of the code, you are free to refer to either the touch objects (that NSSet contains instances of UITouch *
) or the event itself.
I'm not really sure Tim addressed your question so I'll take a shot at it.
touchesCanceled is called when the OS needs to interrupt the user. It gives you a chance to clean up whatever you've been doing in touchesBegan and touchesMoved.
More specifically, it is called when the user puts the phone to his/her face turning the screen off, or if a notification like incoming call or new text message occurs.