IOS hitTest 详解

屏幕上的触摸事件,如果知道是那个视图来响应该事件就是由这个方法来确定

定义

Return Value
The view object that is the farthest descendent the current     view and contains point. Returns nil if the point lies completely     outside the receiver’s view hierarchy.

返回离自己最远的子视图,事件坐标在这个视图内

我认为意思应该是找到最精确的那个位置(view),并且可以通过这个方法来完成一些自定义,比如某个view挡住了另外一个view可以绕过。

具体

This method traverses the view hierarchy by calling the pointInside:withEvent: method of each subview to determine which subview should receive a touch event. If pointInside:withEvent: returns YES, then the subview’s hierarchy is similarly traversed until the frontmost view containing the specified point is found. If a view does not contain the point, its branch of the view hierarchy is ignored. You rarely need to call this method yourself, but you might override it to hide touch events from subviews.

这个方法会在子视图上调用pointInside:withEvent 如果返回YES 则继续最后。
如果NO就中断绕过。

This method ignores view objects that are hidden, that have disabled user interactions, or have an alpha level less than 0.01. This method does not take the view’s content into account when determining a hit. Thus, a view can still be returned even if the specified point is in a transparent portion of that view’s content.

如果视图设置为不交互或者透明度小于0.01该方法会绕过。

Points that lie outside the receiver’s bounds are never reported as hits, even if they actually lie within one of the receiver’s subviews. This can occur if the current view’s clipsToBounds property is set to NO and the affected subview extends beyond the view’s bounds.

如果点击坐标不在视图范围内则绕过,但是如果子视图超出了子图bounds,事件落在在子视图上则执行该事件。
    原文作者:hqman
    原文地址: https://segmentfault.com/a/1190000002812135
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞