获取某些CGPoint下的视图列表

时间:2013-08-29 13:12:43

标签: iphone ios objective-c

我需要获取某些CGPoint上的视图列表。使用此方法:

- (void)handlePan:(UITapGestureRecognizer *)recognizer {
    UIView *subview = [recognizer.view hitTest:[recognizer locationInView:recognizer.view] withEvent:nil];
    //....
 }

只给了我1个视图。有没有办法在该位置下获得一系列视图?

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中运行此代码。