0

I am new to objective C but have created some moving animations in Xcode 5 and now want to make a simple game. I need a way to check if the center point of an image is within a rectangle the catch is it could be within 39 rectangles.

I could check if the center of the image is within each rectangle using CGRectContainsPoint but this would require 39 if stmts. Like this:

if(CGRectContainsPoint(block1.frame, RedAntWorker.center){//found it do something otherwise keep checking}

//do this 39 more times for blockn.frame

I would rather use a for loop with one if stmt. Here is what I want to do:

for (NSInteger i = 0; i < 39; i++) {
 NSString *nameOfImageView = [NSString stringWithFormat:@"block1%d.png", i+1];
    UIImageView *image = nameOfImageView;
    if(CGRectContainsPoint(image.frame, RedAntWorker.center){
        //do some stuff
    }
}

However this is clearly wrong and at run time I get: UIImageView * with an expression of type NSString *

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Brian Bird
  • 1,176
  • 18
  • 21

1 Answers1

0

If all your image views are outlets, you should use an IBOutletCollection as described in this other question.

Community
  • 1
  • 1
Cyrille
  • 25,014
  • 12
  • 67
  • 90