我需要获取某个 CGPoint 上的 View 列表。使用此方法:
- (void)handlePan:(UITapGestureRecognizer *)recognizer {
UIView *subview = [recognizer.view hitTest:[recognizer locationInView:recognizer.view] withEvent:nil];
//....
}
只给我 1 个 View 。有什么办法可以得到location下的view数组吗?
最佳答案
我认为你可以这样做:
NSMutableArray *subviewsList = [NSMutableArray new];
for (UIView *subview in self.view.subviews) {
if (CGRectContainsPoint(subview.frame, point) ) {
[subviewsList addObject:subview];
}
}
point
是您的[recognizer locationInView:recognizer.view]
。当然,假设您在 viewController 中运行此代码。
关于iphone - 获取某个CGPoint下的 View 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18512020/