如何获得给予CGPoint的UIView? [英] How to get UIView given a CGPoint?
问题描述
我正在尝试找到一种获得特定 UIView
的方法,给出 CGPoint
。简而言之,我想做一个热门测试。
I am trying to find a way to get a particular UIView
given a CGPoint
. Briefly, I want to do a hit test.
例如,我有一个 UIView
,其中有很多子视图尺寸小于父 UIView
。我想要做的是,当发生 touchMoved
事件时,检查触摸的子视图周围的其他子视图。
为此目的,能够将 CGPoint
转换为子视图 UIView
会很高兴。
For example, I have a UIView
which has many subviews whose sizes are smaller than the parent UIView
. What I want to do is, when a touchMoved
event happens, to check the other subviews around the touched subview.
For that purpose, it would be nice to be able to convert a CGPoint
to a subview UIView
.
我是Objective-C的新手。有没有好办法呢?任何建议都会非常有用。 :)
I'm new to Objective-C. Is there good way to do it? Any suggestion would be really helpful. :)
推荐答案
有一个 hitTest:withEvent:选择器。这将返回包含该点的视图层次结构中最深的子视图。尝试在最顶层的视图中调用它。
There is a hitTest:withEvent: selector on UIView. This returns the deepest subview in the view hierarchy that contains that point. Try calling this on your topmost view.
这篇关于如何获得给予CGPoint的UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!