我需要获取某个 CGPoint 上的视图列表。使用这种方法:
- (void)handlePan:(UITapGestureRecognizer *)recognizer {
UIView *subview = [recognizer.view hitTest:[recognizer locationInView:recognizer.view] withEvent:nil];
//....
}
只给我 1 个视图。有什么方法可以在该位置下获得一系列视图?
我需要获取某个 CGPoint 上的视图列表。使用这种方法:
- (void)handlePan:(UITapGestureRecognizer *)recognizer {
UIView *subview = [recognizer.view hitTest:[recognizer locationInView:recognizer.view] withEvent:nil];
//....
}
只给我 1 个视图。有什么方法可以在该位置下获得一系列视图?
我认为你可以这样做:
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 中运行此代码。