UI advanced--touch event generation and delivery

Source: Internet
Author: User

The generation and delivery of events:

  • After a touch event occurs, the system adds the event to an event queue managed by the 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 invoked to handle the event in detail;
  • Touchesbegan ...
  • Touchesmoved ...
  • touchedended ...

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

①. Determine if you can receive touch events?

control does not receive three cases of touch events

1> does not receive user interaction Userinteractionenabled=no

2> Hide hidden = YES

3> transparent alpha = 0.0 ~ 0.01

②. Determine if the touch point is on your own?

1, to judge the touch point is not on their own,view has a method "-(BOOL) Pointinside:withevent:"

2, return No, the representative is not on their side, that no longer traverse the child control

3, returns YES, represents the point on its own upward, that continues to traverse the child control

③. Iterate through the child controls backwards, repeating the previous two steps

④. If there are no child controls that meet the criteria, then the control that is most appropriate for your work

⑤. Call the touchesbegin/touchesmoved/touchesended method When you find the most appropriate control

Example of event delivery:

Touch Event Delivery is passed from parent control to child controlClick on the Green View:

UIApplication, UIWindow, white-green

Click on the Blue View:

UIApplication, UIWindow, white-orange blue

Click on the Yellow view:

UIApplication, UIWindow, White, orange and blue

Note: If the parent control cannot receive touch events, the child controls will not be able to receive touch events

UI advanced--touch 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.