iOS Learning Note Touch Event &uiresponderTouch Events
The four methods associated with touch events are as follows:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
Uitouch how objects and events work in the appropriate way
The mechanism for handling touch events in iOS is similar to the message mechanism in Windows. When a touch event occurs in an app, the system adds the event to an event queue, which is managed by the UIApplication Singleton. UIApplication sends a specific Uiresponder message to the view that owns the event, and the view that receives the message is processed further.
Multi Point Touch
By default, views can only receive one touch event at a time. If a finger has already started Touchesbegan:withevent: method, then the other touch events are ignored before the finger leaves the screen (before triggering the Touchesended:withevent: method). To do this, you need to add the following code in the initialization method of the UIView that receives the touch event to allow multi-touch
self.multipleTouchEnabledYES;
Response Object Chain
uiresponder object, in addition to UIView, includes Uiviewcontroller, UIWindow, and uiapplication, which are able to receive events through the Response object chain.
uiresponder object has a pointer named Nextresponder, The associated Uiresponder object can form a chain of response objects, as shown in
When the UIView object belongs to a Uiviewcontroller object, its nextresponder pointer points to the Uiviewcontroller object that contains the view. When the UIView object is not part of any Uiviewcontroller object, its nextresponder pointer points to the view's parent view. The Nextresponder pointer to the Uiviewcontroller object typically points to the parent view of its view. The topmost parent view is the UIWindow object, and the Nextresponder of the UIWindow object points to the UIApplication single case.
If a specific event-handling method is not overridden for a Uiresponder object, the Nextresponder of the object attempts to handle the corresponding touch event. The event is propagated along the chain of response objects, known to the UIApplication object (the last object in the chain of the response object), and discarded if uiapplication cannot handle the event.
iOS Learning Note Touch Event &uiresponder