0

I am using this code to detect when UIButton and UIImageView are overlapping:

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

The code works fine, but I have images B, C, D, E. How can I loop over a collection of them and move CGRectContainsPoint() into the body of that loop?

4

1 回答 1

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.
    }
}
于 2013-04-14T16:44:59.200 回答