[英]Obtain a list of views under certain CGPoint
I need to get a list of views that are on certain CGPoint. 我需要获取某些CGPoint上的视图列表。 Using this method:
使用此方法:
- (void)handlePan:(UITapGestureRecognizer *)recognizer {
UIView *subview = [recognizer.view hitTest:[recognizer locationInView:recognizer.view] withEvent:nil];
//....
}
gives me only 1 view. 只给我一个视图。 Is there any way to get an array of views under the location?
有没有办法在该位置下获得一系列视图?
I think you can do something like this: 我想你可以这样做:
NSMutableArray *subviewsList = [NSMutableArray new];
for (UIView *subview in self.view.subviews) {
if (CGRectContainsPoint(subview.frame, point) ) {
[subviewsList addObject:subview];
}
}
point
is your [recognizer locationInView:recognizer.view]
. point
是你的[recognizer locationInView:recognizer.view]
。 Assuming, of course, you are running this code inside a viewController. 当然,假设您在viewController中运行此代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.