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,事件落在在子视图上则执行该事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值