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