【问题标题】:detect the control/view at the point of touch检测触摸点的控制/视图
【发布时间】:2011-11-09 02:23:29
【问题描述】:

当触摸发生时,我可以从发生触摸的地方获取 CGPoint。现在,我想知道现场的 UI 元素(无论是控件还是视图)是什么,有没有办法做到这一点?

【问题讨论】:

    标签: iphone uiview uicontrol touch-event


    【解决方案1】:

    您正在寻找-[UIView hitTest:withEvent:] 方法:

    返回包含指定点的视图层次结构(包括其自身)中接收器的最远后代。

    【讨论】:

    • 非常感谢!更进一步,我如何判断给定的 CGPoint 是否在两个视图的重叠矩形内?或者在此之前,我怎样才能得到两个视图的重叠矩形?
    • 查看CGGeometry Reference 中的 CGRectIntersection 和 CGRectContainsPoint。您还需要-[UIView convertRect:fromView:]
    猜你喜欢
    • 2013-05-08
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 2014-09-06
    相关资源
    最近更新 更多