iOS Development UI Chapter-Event delivery

Source: Internet
Author: User

iOS Development UI Chapter-Event delivery

I. Generation and transmission 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

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

Ii. example of an event delivery process

Touch event delivery is passed from parent control to child control

Click Green View:uiapplication, UIWindow, White

Click on the Blue View:uiapplication, UIWindow, White, orange

Click on the Yellow view:uiapplication, UIWindow, White, orange

Note: child controls cannot receive touch events if the parent control cannot receive touch events

How do I find the most appropriate control to handle an event?

(1) Can I receive touch events?

(2) is the touch point on its own?

(3) Iterate through the child controls, repeating the previous two steps

(4) If there are no child controls that meet the criteria, then you are best suited to handle

Example:

Set up the following interface, each of which is managed by a single class for each custom view.

Create a new base class that inherits from view, and let other custom view inherit from the class, overriding the following code in the class.

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event

{

NSLog (@ "%@", Self.class);

}

Iii. three cases of not accepting touch events

(1) Do not receive user interaction userinteractionenabled = no

(2) Hide hidden = YES

(3) Transparent alpha = 0.0 ~ 0.01

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

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.