Main content: Event handling (touch, responder chain)
I. Basic concepts of events
Uievent: Event, which is a hardware-captured object that represents a user-operated device
Divided into three categories: touch events, shaking events, remote control events
Touch events: Users manipulate objects and enter data by touching the device screen. Multi-Touch support
The concept of touch:
UIView supports touch events (because it inherits from Uiresponder) and supports multi-touch
Need to define the UIView subclass to implement touch-related methods
Touches...began//Start Touch
Touches...moved//During touch
touches...ended//End Touch
touches...canceled//Touch Pause
Use touch to implement gestures:
Gestures: a regular touch
Uitouch represents touching a finger on the screen to get the touch time and position
Second, the responder chain
Chain consisting of multiple responder objects
Uiresponder: Responder Class
All objects in iOS that respond to events (touch, shake, remote events) are response events
The system defines an abstract parent class Uiresponder to represent the responder, whose subclass is the responder
To detect a touch view:
The hardware detects a touch operation and passes the information to the uiapplication to begin detection
UIApplication->window->viewcontroller->view, detect all sub-views, finalize the contact location and complete the query process of the responder chain
When a responder is detected, implement methods such as Touchesbegan:withevent, that is, handling events
If the responder does not handle the event, the event is passed down and if no responder handles the event, the touch event is discarded
the sequence of event handling is the opposite of a touch detection query
Touch Child View->view->viewcontroller->window->uiapplication
Four Methods
//Start Touch
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
}
//During the touch process
-(void) touchesmoved: (Nsset *) touches withevent: (uievent) event
{
}
//Touch Stop
-(void) touchesended: (Nsset *) touches withevent: (uievent) event
{
}
//Touch Pause
-(void) touchescanceled: (Nsset *) touches withevent: (Uievent *) event
{
}
UI Fourth Lesson