2012-07-06 126 views
0

有沒有辦法快速獲取視圖(包含)UITouch的特定點?我有相對於self.view的座標,但想知道當時的任何/所有視圖。我的看法層次類似於獲取位於觸摸位置的uiview

  • self.view
    • 滾動型
      • 視圖
      • 視圖

回答

1

可以使用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)視圖檢查,並返回一個布爾值。

+0

謝謝,這些都很好看。我還在hitTest上找到了一些信息:這也可能起作用。 – 2012-07-09 19:57:48