【问题标题】:Get the uiview that is at the location of a touch获取触摸位置的uiview
【发布时间】:2012-07-06 19:12:01
【问题描述】:

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

  • self.view
    • 滚动查看
      • 查看
      • 查看

【问题讨论】:

    标签: ios xcode uiview uitouch


    【解决方案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) 进行检查并返回一个布尔值。

    【讨论】:

    • 谢谢,这两个看起来都不错。我还在 hitTest 上找到了一些信息:这也可能有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多