17

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. :)

jscs
  • 63,694
  • 13
  • 151
  • 195
Aki24x
  • 1,058
  • 1
  • 13
  • 28

1 Answers1

22

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.

jjwchoy
  • 1,898
  • 16
  • 20