iOS Response chain principle

Source: Internet
Author: User

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

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.