Determining Which Responder Contained a Touch Event。
决定哪一个responder包含触摸事件。
UIKit uses view-based hit-testing to determine where touch events occur. Specifically, UIKit compares the touch location to the bounds of view objects in the view hierarchy. The hitTest(_:with:) method of UIView traverses the view hierarchy, looking for the deepest subview that contains the specified touch, which becomes the first responder for the touch event.
UIKit利用view-based hit-testing 决定触摸事件在哪里发生。具体来说,UIKit将触摸位置与视图层次结构中试图对象的边界进行比较。遍历视图层次结构的hitTest(_:with:)方法,寻找最深的包括触摸的子视图,它会变成事件的第一响应者。
Note
If a touch location is outside of a view’s bounds, the hitTest(_:with:) method ignores that view and all of its subviews. As a result, when a view’s clipsToBounds property is false, subviews outside of that view’s bounds are not returned even if they happen to contain the touch. For more information about the hit-testing behavior, see the discussion of the hitTest(_:with:) method in UIView.
如果一个触摸点是在视图的边界之外,这 个hitTest(_:with:) 方法会忽略这个视图,以及他的所有子视图。结果就是,一个视图的clipsToBounds为false的时候,视图bounds外边的所有子视图都不会被返回,尽管他们包含了触摸事件。
When a touch occurs, UIKit creates a UITouch object and associates it with a view. As the touch location or other parameters change, UIKit updates the same UITouch object with the new information. The only property that does not change is the view. (Even when the touch location moves outside the original view, the value in the touch’s view property does not change.) When the touch ends, UIKit releases the UITouch object.
当一个触摸事件发生的时候,UIKit会创建一个UITouch对象,把它与一个视图绑定。当触摸位置或者其他参数变化的时候,UIKit会用新的信息更新更新同样的UITouch对象;