iOS development-event generation and delivery

Source: Internet
Author: User

Generation and delivery of events

After a touch event occurs, the system adds the event to an event queue managed by UIApplication

UIApplication takes the first event from the event queue and distributes the event for processing, typically sending an event to the application's main window (Keywindow)

The main window will find the most appropriate view in the view hierarchy to handle touch events, which is the first step in the entire event processing process.

Once the appropriate view control is found, the touches method of the view control is called to do the specific event handling

touchesBegan…touchesMoved…touchedEnded…
UIView three cases of not receiving touch events

1. Do not receive user interaction

userInteractionEnabled = NO;

2. Hide

hidden = YES;

3. Transparent

alpha = 0.0 ~ 0.01

Tip: Uiimageview's userinteractionenabled default is no, so Uiimageview and its child controls cannot receive touch events by default.

Detailed process of touch event handling

A touch event that occurs after a user taps the screen and, after passing through some columns, finds the most appropriate view control to handle the event

Once the most appropriate view control is found, the touches method of the control is called to make specific event handling

touchesBegan…touchesMoved…touchedEnded…

The default practice of these touches methods is to pass the event up the responder chain, handing the event to the previous responder for processing

Responder Chain

The event delivery process for the responder chain

If the view controller is present, it is passed to the controller, and if the controller does not exist, it is passed to its parent view
In the top-most view of the view hierarchy, if you cannot process the received event or message, it passes the event or message to the Window object for processing
If the window object is not processed, it passes the event or message to the UIApplication object
If UIApplication cannot process the event or message, it is discarded

The practice of listening for touch events

If you want to listen to a touch event on a view, the previous practice is to
Customizing a View
Implement the touches method of view, implement the specific processing code inside the method

There are a few obvious drawbacks to monitoring the view touch event through the touches method
You have to customize the view
Because the touch event is monitored in the touches method inside the view, it is not possible to allow other external objects to listen to the touch events of the view by default
Not easily differentiate user's specific gesture behavior

After IOS 3.2, Apple introduced the gesture recognition feature (Gesture recognizer), which greatly simplifies developer development in touch event handling

iOS development-event generation and delivery

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.