The event delivery process for the responder chain

Source: Internet
Author: User

The event delivery process for the responder chain
First,Hittext Method
1.the Hittext methodwhen an event is passed to a control, the control calls this method
2.Hittextfunction: to find the most suitableView.
3. Hittext Method
1),determine if the window can handle events? if not, it means that the window is not the most suitableView, and will not find a better fit than yourself.View,Direct returnNil,Noticeuiapplication, there is no most suitableView.
2),determine if the touch point is not in the window.
3),Traverse your own child controls to find out if there is more appropriate than yourselfView
4),If the child control does not receive an event, it means that the child control does not find the most appropriateView,and then returnNil,tell the window not to find a more appropriateView,window to know that there is no more appropriate than yourselfView,handle events on your own.

//find the right one.View
// Pointis whiteViewthe point on the coordinate system
- (UIView*) HitTest: (Cgpoint) point withevent: (uievent*) Event
{
//1.determine if you can receive events
if( Self.userinteractionenabled==NO|| Self.Hidden==YES|| Self.Alpha<=0.01)returnNil;

//2.Judging points are not on the current control
if(![ SelfPointinside:p ointwithevent: event])returnNil;

//3.to find out if there's anything more appropriate than yourself.View
//Traverse your own child controls from the back
intcount = Self.subviews.Count;

for(inti = count-1; I >=0; i--) {
//Get child controls
UIView*childview = Self.subviews[i];

//Convert coordinate system
//convert points in your coordinate system to sub-controls to make points on the coordinate system
CgpointChildpoint = [ SelfConvertpoint:p ointToview: Childview];

UIView*fitview = [ChildviewhitTest: Childpointwithevent: event];
//find the most suitableView
if(Fitview) {
returnFitview;
}
}
//I didn't find a better fit than myself.View
return Self;
}

/**
*  The point of judgment is not in the coordinate system of the method caller
* Point:is the point on the coordinate system of the method caller
*/
- (BOOL) Pointinside: (Cgpoint) point withevent: (uievent*) Event
{
return NO;
}
Note: 1,touch The default practice: Do not handle themselves, to the previous responder.   2 . The previous responder is the parent control by default.

second, the event delivery process of the responder chain:1.ifViewController is present, it is passed to the controller, and if the controller does not exist, it is passed to its parent view.
2.in the top-most view of the view hierarchy, if you cannot process the received event or message, it passes the event or message to thewindowobject for processing
3.ifwindowobject is not processed, it passes an event or message to theuiapplicationObject
4.ifuiapplicationthe event or message cannot be processed, it is discarded.

The event delivery process for the responder chain

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.