title: How to detect if image is touched
body: <p>How can you detect if an image is touched in Xcode? I have looked at Apple documentation and it is really confusing...
  I saw:</p>
  
  <pre><code>if (CGRectContainsPoint([imageView frame], location))
  </code></pre>
  
  <p>but my image still won't move. I tried using touchesBegan + touchesMoved, and set the image's userInteractionIsEnabled to YES, but it still won't detect it :(</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> Thank you all so much for your great suggestions! In the end, I really wanted to make it as simple as possible, and I knew that my code <em>should</em> work, so I kept fiddling with it, and after a good night's sleep, I realized it was a fairly simple solution:</p>
  
  <p>In my touchesMoved:</p>
  
  <pre><code>    UITouch *touch = [[event allTouches] anyObject];
      CGPoint location = [touch locationInView:touch.view];
  
      CGRect shapeRect = [imageView frame];
      CGRect dropSquareRect = [dropSquare frame];
  
      CGPoint touchLocation = CGPointMake(location.x, location.y);
  
      if (CGRectContainsPoint(shapeRect, touchLocation))
      {
          [UIView beginAnimations:nil context:nil];
          [UIView setAnimationDuration:.3];
          [imageView setCenter:touchLocation];
          [UIView commitAnimations];
      }
  
      if (CGRectIntersectsRect(shapeRect, dropSquareRect))
      {
          [UIView beginAnimations:nil context:nil];
          [UIView setAnimationDuration:.3];
          [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
          self.imageView.alpha = 0;
          self.imageView.center = CGPointMake(dropSquare.center.x, dropSquare.center.y);
          self.imageView.transform = CGAffineTransformMakeScale(0.8, 0.8);
          [UIView commitAnimations];
  </code></pre>