The event Transfer Process of the responder chain, and response event Transfer
Event Transfer Process of the responder chain
1. hitText Method
1. The hitText method calls this method when an event is passed to a control.
2. hitText: Find the most appropriate view.
3. hitText Method
1) Can I determine whether the window can handle the event? If not, it means that the window is not the most suitable view, and it does not look for a view that is more suitable than itself. nil is returned directly, notifying UIApplication that there is no most suitable view.
2) determine that the touch point is not in the window.
3) traverse your child control and find out if there is a more appropriate view than yourself.
4) if the child control does not receive events, it means that the child control does not find the most appropriate view, and then returns nil, telling the window that a more appropriate view is not found, the window knows that there is no more appropriate view than itself, and you can handle the event by yourself.
// Find the most appropriate view
// Point is the point in the coordinate system of the white View.
-(UIView *) hitTest :( CGPoint) point withEvent :( UIEvent *) event
{
// 1. Determine whether you can receive the event
If (self. userInteractionEnabled = NO | self. hidden = YES | self. alpha <= 0.01) returnnil;
// 2. The judgment point is not on the current control.
If (! [SelfpointInside: pointwithEvent: event]) returnnil;
// 3. Find a view that is more suitable than yourself.
// Traverse the child control from the back to the front
Intcount = self. subviews. count;
For (inti = count-1; I> = 0; I --){
// Obtain the child Control
UIView * childView = self. subviews [I];
// Convert the Coordinate System
// Convert the points in the coordinate system into child controls for the points in the coordinate system
CGPointchildPoint = [selfconvertPoint: pointtoView: childView];
UIView * fitView = [childViewhitTest: childPointwithEvent: event];
// Find the most appropriate view
If (fitView ){
ReturnfitView;
}
}
// No more appropriate view found
Returnself;
}
/**
* The Judgment point is not in the coordinate system of the method caller.
* Point: the point in the coordinate system of the method caller.
*/
-(BOOL) pointInside :( CGPoint) point withEvent :( UIEvent *) event
{
Return NO;
}
Note: 1. touch's default practice: do not handle it by yourself and give it to the last responder. 2. The previous responder is the parent control by default.
2. Event Transfer Process of the responder chain: 1. If the controller of the view exists, it is passed to the Controller; if the Controller does not exist, it is passed to its parent view.
2. In the top-level view of the view hierarchy, if the received event or message cannot be processed, the event or message is transmitted to the window object for processing.
3. If the window object is not processed, it will pass the event or message to the UIApplication object.
4. If UIApplication cannot process this event or message, discard it.