The process of finding the clicked view by iOS is to call the hit Test method recursively from the root view until the HitTest method of a child view returns itself, and if all the hittest methods of the first-level child view return nil, Then the root view will return to itself .
Applying the hitTest method, the function of the HitTest method is to return the clicked View, returning only one.
Each view will have a HitTest method,HitTestMethod inside will callPointinsidemethod to determine whether the clicked point is in its ownViewIn the range, hitTestReturn to itselfviewhittest method is called, its own pointinside method returns trueviewviewview hittest method, which is said to be possible because if the parent view userinteractionenabled = = NO view method will not be called )
HitTest Method Approximate Content
-(uiview*) HitTest: (cgpoint) point withevent: (uievent*) Event {
Some judgment conditions, such as userinteractionenabled = = NO, return nil directly
if ([self pointinside:point withevent:event]) {
For (UIView *subview in self.subviews) {
UIView *hitview = [SubView hittest:point withevent:event];
if (Hitview) {
return hitview;
}
}
return self;
}
return nil;
}
iOS Response chain principle