title: How to check whether a CGPoint is inside a UIImageView?
body: <p>In <code>touchesBegan:</code></p>
  
  <pre><code>CGPoint touch_point = [[touches anyObject] locationInView:self.view];
  </code></pre>
  
  <p>There are tens of <code>UIImageView</code> around, stored in a <code>NSMutableArray</code> <code>images</code>. I'd like to know is there a built-in function to check if a <code>CGPoint</code> (touch_point) is inside one of the images, e.g.:</p>
  
  <pre><code>for (UIImageView *image in images) {
     // how to test if touch_point is tapped on a image?
  }
  </code></pre>
  
  <p>Thanks</p>
  
  <p>Follow up:</p>
  
  <p>For unknown reason, <code>pointInside</code> never returns true. Here is the full code.</p>
  
  <pre><code>    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
      { 
        UITouch *touch = [touches anyObject]; 
          touch_point = [touch locationInView:self.view];
          for (UIImageView *image in piece_images) {
              if ([image pointInside:touch_point withEvent:event]) {
                  image.hidden = YES;
              } else {
                  image.hidden = NO;
              }
              NSLog(@"image %.0f %.0f touch %.0f %.0f", image.center.x, image.center.y, touch_point.x, touch_point.y);
          }
      } 
  </code></pre>
  
  <p>although I can see the two points are sometimes identical in the <code>NSLog</code> output.</p>
  
  <p>I also tried:</p>
  
  <pre><code>  if ([image pointInside:touch_point withEvent:nil]) 
  </code></pre>
  
  <p>the result is the same. never returns a true.</p>
  
  <p>To eliminate the chance of anything goes with with the images. I tried the following:</p>
  
  <pre><code>  if (YES or [image pointInside:touch_point withEvent:event])
  </code></pre>
  
  <p>all images are hidden after the first click on screen.</p>
  
  <p>EDIT 2:</p>
  
  <p>Really weird. Even I hard coded this:</p>
  
  <pre><code>        point.x = image.center.x;
          point.y = image.center.y;
  </code></pre>
  
  <p>the code becomes:</p>
  
  <pre><code>    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
      { 
          UITouch *touch = [touches anyObject]; 
          CGPoint point; // = [touch locationInView:self.view];
          for (UIImageView *image in piece_images) {
              point.x = image.center.x;
              point.y = image.center.y;       
              if ([image pointInside:point withEvent:event]) {
                  image.hidden = YES;
                  NSLog(@"YES");
              } else {
                  image.hidden = NO;
                  NSLog(@"NO");
              }
              NSLog(@"image %.0f %.0f touch %.0f %.0f", image.center.x, image.center.y, point.x, point.y);
          }
      }
  </code></pre>
  
  <p><code>pointInside</code> always returns <code>false</code> ... </p>