I. Basic concepts of events1. Overview of Events
- 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 system passes an event to a specific path to an object that can be processed.
- In iOS rollup, a Uitouch object represents a touch, and a uievent represents an event. The event object contains all the touch objects that correspond to the current multi-touch order and can also provide touch objects associated with a particular view or window.
- There are three types of events: Touch events, shaking events, remote events.
Second, the basic concept of touch1. Touch Overview
- 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 is lifted from the screen. The touch information also includes the location information currently in the View window, as well as the 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.
2, the processing method of touch timeIn a given touch phase, if a new touch action occurs or an existing touch action changes, the application sendssend these messages:
- Send touchesbegan:withevent: Message when one or more fingers touch the screen.
- Send touchesmoved:withevent: Message when one or more fingers move on the screen.
- Send touchesended:withevent: Message when one or more fingers leave the screen.
Third, the responder chain
1. Overview of the responder chain
- A responder chain is a sequence of links to a responder object, in which time or action messages (or menu-editing messages) are passed in turn. It allows the responder object to transfer responsibility for event handling to other higher-level objects. The application finds the appropriate processing object by passing an event up. Because click Detection view is also a responder object, the application can also take advantage of the response chain when dealing with touch events.
- A chain consisting of multiple responder objects.
2. Respondents
- All objects in iOS that respond to events (touch, shake, remote events) are responders.
- The system defines an abstract parent class Uiresponder to represent the responder. Its subclasses are the respondents.
3. Detect Collision View
- The hardware detects a touch operation and gives the information to uiapplication to begin detection.
- Uiapplication->window->viewcontroller->view-> Detect all child views
- Finally confirm the contact location, complete the response chain of the query process.
- Icon:
4. Handle Touch Events
- After the responder is detected, implement Touchesbegan:withevent: And so on, that is, processing the event.
- If the responder does not handle the event, the event is passed down. If there is no responder processing, the touch event is discarded.
- The order of event processing is the opposite of a touch detection query.
- Touch the child view->view->viewcontroller->window->uiapplication.
5, blocking the response chain
- The responder chain can be interrupted. Can't
- Ionenabled. Shut down to block the query process.
- Userinteractionenabled will block the process of view detection, default does not block
- Value isNO , starting from the current view to all child views no longer detects viewb.< Span style= "color: #ff2600;" >=
6, the responder chain processing principle
- Click Detect View or the first responder passes the event or action message to its view controller (if it has one), and if it does not have a view controller, it is passed to its parent view.
- If a view or its view controller cannot handle this event or action message, it is passed to the parent view of the view.
- Each successive parent view in this view hierarchy follows the above pattern if it cannot handle this event or action message.
- The topmost view spits over the inability to handle this event or action message and passes it to the UIWindow object for processing.
- If the UIWindow object cannot be processed, it is passed to the single-piece Application object UIApplication if the Application object cannot handle the event or action message, it will be discarded.
Iv. gestures1. Gesture Recognizer Overview
- Gesture recognizer is the encapsulation of touch events, the gesture recognizer itself plays a role in recognition.
- Gesture recognizer is a class called abstract in iOS, used to identify a gesture called gestures: a regular touch.
2. Gesture classification: Tap gesture, long press gesture, rotate gesture, pinch gesture, pan gesture, swipe gesture, screen border shift gesture. 3, using gesture Recognizer: system-provided gesture recognizer This abstract parent class is not used directly, but instead uses a specific gesture recognizer to create objects based on demand, and the system provides the following types of gestures:
- The UITapGestureRecognizer is a pat gesture recognizer that recognizes the tap operation;
- Uilongpressgesturerecognizer is a long press gesture recognizer, which can recognize long press operation;
- Uirotationgesturerecognizer is a rotary gesture recognizer that can recognize rotation operations;
- Uipinchgesturerecognizer is a pinch gesture recognizer that can identify pinch operations;
- Uipangesturerecognizer is a translational gesture recognizer that can recognize drag and drop operations;
- The Uiswipegesturerecognizer is a swipe gesture recognizer that can recognize drag-and-drop operations;
- Uiscreenedgepangesturerecognizer is the screen edge swipe recognizer.
4. Create gesture recognizer
- To create a Uixxxgesturerecognizer object, use the Initwithtarger:action: method
- Configure information about the gestures to be recognized
- To add a gesture to a view
- Implement the method defined in the gesture recognizer
5. Transform attribute of view
- Transform is an important attribute of view, it changes the display state of view at the matrix level, and can realize the function of zooming, rotating and panning of view.
- Pan: cgaffinetransformmaketranslation
- Scaling: Cgaffinetransformmakescale
- Rotation: cgaffinetransformmakerotation
- Part of the gesture code example:
iOS Learning event Handling