有人可以帮助我如何从给定的 X,Y 坐标检索 iOS UI 元素属性吗?
谢谢。
最佳答案
一般来说,您需要 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
UIView
的消息。如果您的 x, y
在窗口坐标中,您可以使用窗口的 View :
UIView *view = [myWindow.rootViewController.view hitTest:CGPointMake(x, y) withEvent:nil];
这将使 view
成为该位置 View 层次结构中最远的元素。您需要确保坐标位于元素的空间内。
如果您怀疑该元素,您可能还会喜欢- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
。
关于ios - UI 元素坐标到 UI 元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14344416/