获取触摸位置的uiview

时间:2012-07-06 19:12:02

标签: ios xcode uiview uitouch

有没有办法快速获取(包含)UITouch特定点的视图?我有相对于self.view的坐标,但想知道那时的任何/所有视图。我的视图层次结构类似于

  • self.view
    • 滚动视图
      • 视图
      • 视图

1 个答案:

答案 0 :(得分:2)

您可以使用CGRectContainsPoint()方法。 此方法将返回一个布尔值。 您需要传递视图框架(CGRect)和相对于触摸的坐标(CGPoint)。

https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html#//apple_ref/c/func/CGRectContainsPoint

您也可以使用此方法查看,

CGPoint aPoint = //your touch point;
BOOL isPointInsideView = [yourView pointInside:aPoint withEvent:nil];

这里使用您给出的视图(aPoint)检查给定点(yourView)并返回一个布尔值。