[IOS UI advanced, iosui advanced

Source: Internet
Author: User

[IOS UI advanced, iosui advanced
A. generation and transmission of eventsAfter a touch event occurs, the system adds the event to an event queue managed by UIApplication.

UIApplication extracts the first event from the event queue and distributes the event for processing. Generally, it sends the event to the application's main window (keyWindow) first)

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

After a proper view control is found, the touches method of the View control is called for specific event processing.
TouchesBegan...
TouchesMoved... TouchedEnded...B. events not acceptedDo not receive user interaction
UserInteractionEnabled = NO

Hide
Hidden = YES

Transparent
Alpha = 0.0 ~ 0.01

Tip: userInteractionEnabled of UIImageView is NO by default. Therefore, UIImageView and its sub-controls cannot receive touch events by default.C. Processing of touch eventsA touch event generated when you click on the screen. After passing through some columns, you will find the most appropriate view control to handle this event.

After finding the most appropriate view control, the touches method of the control is called for specific event processing.
TouchesBegan...
TouchesMoved...
TouchedEnded...

The default method of these touches methods is to pass the event up the responder chain and send the event to the last responder for processing.D. responder chain

For the app on the left, the event follows this path:

The app on the right follows a slightly different path, but all event delivery paths follow these heuristics:

For the app on the left, the event track is like this: (single Controller) 1. the initial control attempts to process events or information. If it cannot process events, the initial control is passed to its parent control because it is not the top-level control of the control layer of the Control. 2. the "parent control" also tries to follow up the handling event. If the "parent control" still cannot be processed, because this "parent control" is not the top-level control of the controller control layer, therefore, this event will also be passed to its parent control (well, the "master control" of the initial control "). 3. The top-level control of the controller space layer obtains the event and tries to handle it. If it still does not have this capability, it will be passed to the Controller to which it belongs. 4. the controller does not work yet. It can only be passed to the window. 5. if window cannot be processed, it will continue to be passed to the app singleton object (Application) 6. if the app cannot handle the event at the end, the event can only be abandoned. For apps on the right, the event track is slightly different, but they all follow the following rules: (multiple controllers) 1. A control transmits events at the controller control level. In this control layer, the control that matches the control with processing capabilities is passed until it reaches the top-level control. 2. The top-level control of the control layer cannot be processed. The event is passed to the Controller. 3. If the Controller of "2" cannot process the event, pass the event to its parent control, repeat 1-3 until the event is processed, or reach the root controller. 4. If the root controller cannot process the event, pass the event to the window object. 5. If the window object cannot be processed, pass the event to the application object. 6. The app cannot process the event at the end. Discard the event. D. Listen for touch eventsIf you want to listen to the touch event on a view, the previous method is
Customize a view
Implement the touches method of view and implement the specific processing code inside the Method

Using the touches method to listen to view touch events has several obvious disadvantages.
You must customize the view.
Because the touches method inside the view listens to touch events, by default, other external objects cannot listen to the view touch events.
It is not easy to differentiate users' specific gesture Behaviors

After iOS 3.2, Apple launched the Gesture Recognizer feature, which greatly simplifies developers' development difficulty in terms of touch event processing:

Related Article

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.