[IOS] The role and usage of hittest

Source: Internet
Author: User

The role of hittest: When a screen mask is added to a view without affecting the operation of the following view, that is, the following view can be operated through the screen mask, this function is very useful.

 

Hittest usage: Add the following function to the subclass of uiview, that is, the shielding class.

 

-(ID) hittest :( cgpoint) Point withevent :( uievent*) Event

{

    Uiview* Hitview = [SuperHittest: PointWithevent: event];

    If(Hitview =Self)

    {

        ReturnNil;

    }

    Else

    {

        ReturnHitview;

    }

}

From: http://blog.sina.com.cn/s/blog_446da0320100yw9u.html

Another article:

Uiview touch event transfer-(bool) pointinside :( cgpoint) Point withevent :( uievent *) event {}This function is used to determine whether the current click or touch event point is in the current view. It is called by hittest: withevent:. You can call pointinside: withevent for each subview to determine which view to respond to this event. If pointinside: withevent: Yes is returned, the inheritance tree of the sub-view is traversed. (In the traversal order, the most responsive view is the view closest to the user. It starts from the top-level subview), that is, the subview of the subview continues to call the recursion function until the subview that can respond is found (the hittest: withevent: will return self instead of Nil); otherwise, the inheritance tree of the view will be ignored. When we need to override the inheritance class uiviewinherit of a uiview, if we need to rewrite the hittest: withevent: method, will there be a question about calling the [Super hittest: withevent:] method? Whether or not it needs to be determined depends on the specific requirements. Here we only describe the effects of the adjustment and not the adjustment. If this parameter is not called, The rewritten method hittest: withevent: only the overwritten code is called, and self or nil is returned Based on the rewritten code, if self is returned, your uiviewinherit class will accept your buttons and then call the touches series method. Otherwise, the NIL will be returned, and the buttons passed to the uiviewinherit class will end here, it does not accept the buttons given by its parent view, that is, it does not call the touches series method. In this case, pointinside: withevent: has almost no effect. If you call this method, the [Super hittest: withevent:] method first determines whether to recursively call the hittest: withevent: Method of all child views based on the value of pointinside: withevent. The same is true for the hittest: withevent: method call of the sub-view. The procedure continues recursion until the hittest: withevent of the sub-view at the first recursive level is found: the method returns non-nil. At this time, the call ends and the touches series method of the Child view is called.  If we don't want a view to respond to an event, we just need to overload pointinside: withevent: Method to let this method return no. However, we still cannot understand the purpose of the hittest: withevent method.Invalid Implementation of hittest: withevent: In uiresponder does the following: It cballs pointinside: withevent: Of selfif the return is no, hittest: withevent: returns nil. the end of the story. if the return is yes, it sends hittest: withevent: messages to its subviews. it starts from the top-level subview, and continues to other views until a subview returns a non-Nil object, or all subviews receive the message. if a subview returns a non-Nil object in the first time, the first hittest: withevent: returns that object. the end of the story. if no subview returns a non-Nil object, the first hittest: withevent: returns selfthis process repeats recursively, so normally the leaf view of the view hierarchy is returned eventually. however, you might override hittest: withevent to do something differently. in your cases, overriding pointinside: withevent: is simpler and still provides enough options to tweak event handling in your application.

Related Article

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.