How to get UIView given a CGPoint?

為{幸葍}努か 提交于 2019-11-30 22:47:44

问题


I am trying to find a way to get a particular UIView given a CGPoint. Briefly, I want to do a hit test.

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.

I'm new to Objective-C. Is there good way to do it? Any suggestion would be really helpful. :)


回答1:


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.



来源:https://stackoverflow.com/questions/6033220/how-to-get-uiview-given-a-cgpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!