iOS Touch Event Summary

Source: Internet
Author: User
Tags uikit

I. about the basic knowledge of event delivery

1. The UIView class is a subclass of Uiresponder, so it is able to receive touch events that occur when the user interacts with the view content. The touch event starts with the view of the touch and passes along the responder chain until it is finally processed.

The view itself is the responder, the participant in the responder chain, so you can receive the touch events distributed to them by all associated sub-views.

2. By Default, the view responds to only one touch action at a time. If the user places a second finger on the screen, the touch event is ignored and it is not reported to the View object. If you want to track multi-touch gestures in the view's event handler method, you need to reactivate the Multitouch event by setting the view's Multipletouchenabled property declaration to YES. such as the label and Image View, in the initial state completely prohibit event processing. You can control whether the view can handle the event by changing the value of the view's Userinteractionenabled property. When a long-consuming operation is suspended, you can temporarily set this property to NO

3. When handling touch events, Uikit will use UIView's hittest:withevent: and Pointinside:withevent: Method to determine whether the touch event occurs on the specified view

Second, event processing

1. Events and touches

In the iphone OS, touch action refers to the finger touching the screen or moving on the screen, which is part of a multi-touch sequence. For example, a pinch-close gesture contains two touch actions: The two fingers on the screen move in opposite directions. Some single-finger gestures are simpler, such as tapping, double-clicking, or swiping (that is, the user quickly touches the screen). Applications can also recognize more complex gestures, for example, if an application uses a custom control with a carousel shape, the user needs to "turn" the carousel with multiple fingers to make some sort of fine tune.

An event is an object that the system constantly sends to the application when the user's finger strikes the screen and moves on the screen. The event object provides a snapshot of all touch actions in a multi-touch sequence, the most important of which is the new or changed touch action in a particular view. A multi-touch sequence starts with the first finger touching the screen, and the other fingers may then touch the screen, and all fingers may move on the screen. When the last finger leaves the screen, the sequence ends. At each stage of the touch, the application receives the event object.

Touch information has both time and space, and the time information is called the stage (phrase), which indicates whether the touch has just begun, is moving or is in a stationary state, and when it ends-that is, when the finger lifts from the screen (see Figure 3-1). Touch information also includes current position information in the View or window, as well as previous location information, if any. When a finger touches the screen, the touch is associated with a window or view, and the association is maintained throughout the life of the event. If more than one touch occurs at the same time, only the touch associated with the same view will be processed together. Similarly, if two touch events occur at short intervals, they are processed as multi-strike events only if they are associated with the same view.

Figure 3-1多-point touch sequence and touch stage

In the iphone OS, a Uitouch object represents a touch, and a uievent object represents an event. The event object contains all the touch objects that correspond to the current multi-touch sequence, and can also provide touch objects associated with a particular view or window (see Figure 3-2). In a touch sequence

During the process, the touch object that corresponds to a particular finger is persistent, and uikit modifies it as it tracks the movement of the finger. A changed touch attribute variable has a touch stage, a touch position in the view, a position before the change, and a timestamp. The event-handling code determines how to respond to events by examining the values of these properties.

Figure 3-2 relationships between Uievent objects and their Uitouch objects

The system may cancel the multi-touch sequence at any time, and the application that handles the event must be prepared for the correct response. The cancellation of the event may be caused by overloaded system events, which is an example of call-in.

2. Transmission of events

iOS Touch Event Summary

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.