检测手指,UIButton和UIImageView是否重叠

时间:2013-04-14 16:42:11

标签: ios objective-c cgrect

我使用此代码来检测UIButtonUIImageView何时重叠:

CGPoint fingerPoint = [(UIPanGestureRecognizer*)sender locationInView:imageA.superview];
    if (CGRectContainsPoint(imageA.frame, fingerPoint)) {
        NSLog(@"Do something");
    }

代码工作正常,但我有图像B,C,D,E。 如何循环它们的集合并将CGRectContainsPoint()移动到该循环的主体中?

1 个答案:

答案 0 :(得分:0)

NSArray* images = @[ imageA, imageB, imageC, imageD, imageE ];
for (UIImageView* image in images) {
    CGPoint fingerPoint = [(UIPanGestureRecognizer*)sender locationInView:[image superview]];
    if (CGRectContainsPoint(image.frame, fingerPoint)) {
        // Do something.
    }
}