hitTest的作用:当在一个view上添加一个屏蔽罩,但又不影响对下面view的操作,也就是可以透过屏蔽罩对下面的view进行操作,这个函数就很好用了。
hitTest的用法:将下面的函数添加到UIView的子类中,也就是屏蔽罩类中即可。
-(id)hitTest:(CGPoint)point withEvent:(UIEvent
{
}
转自:http://blog.sina.com.cn/s/blog_446da0320100yw9u.html
另外转一个相关的文章:
UiView touch事件传递
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
}
http://blog.sina.com.cn/s/blog_87bed3110100t5cf.html
http://blog.csdn.net/iefreer/article/details/4754482
hitTest:withEvent:调用过程
The implementation of hitTest:withEvent: in UIResponder does the following:
It calls pointInside:withEvent: of self
If 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 self
This 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 many cases, overriding pointInside:withEvent: is simpler and still provides enough options to tweak event handling in your application.