iOS Learning Note Touch Event &uiresponder

Source: Internet
Author: User

iOS Learning Note Touch Event &uiresponderTouch Events

The four methods associated with touch events are as follows:

    • Touch the screen with one finger or multiple fingers

     -(void)touchesBegan:(NSSet *)touches               withEvent:(UIEvent *)event;
    • Move on the screen with one or more fingers (The associated object will continue to send the message as the finger moves)

 -(void)touchesMoved:(NSSet *)touches           withEvent:(UIEvent *)event;
    • Leave the screen with one finger or multiple fingers

 -(void)touchesEnded:(NSSet *)touches           withEvent:(UIEvent *)event;
    • A system event (such as a call coming in) interrupts the touch process until the touch operation ends normally

 -(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.