title: iPhone iOS calculate location within a UIScrollView with zooming
body: <p>I have a color map within a UIScrollView and am trying to sample the color of a pixel of this map. The sample reticle is positioned above the scrollview, while the user moves the contents of the scrollview under the reticle. </p>
  
  <p>The user can drop the reticle with a tap gesture, but I would like to offer an extra option of moving the view under the reticle.</p>
  
  <p>I'm trying to find out <strong>how I can understand what x,y coordinate of the zoomed view is currently under the reticle</strong>. The logic for this so far eludes me, especially since zooming in/out is involved. </p>
  
  <pre><code>-(void)scrollViewDidScroll:(UIScrollView *)scrollView
  {
  
      CGPoint mapLocation = [tapGestureRecognizer locationInView:self.surfaceMap];
  
       NSLog(@"mapLocation (x,y) %.0f,%.0f",mapLocation.x,mapLocation.y);
  
      NSLog(@"contentOffset (x,y) %.0f,%.0f",self.scrollView.contentOffset.x,self.scrollView.contentOffset.y);
  
      //calculate where the marker is pointing to in the surface map while the scrollview is scrolling
  
      int frameWidth = self.surfaceMap.frame.size.width;
      int frameHeight = self.surfaceMap.frame.size.height;
  
  //this is what I'm trying to calculate
      CGPoint trueLocation = CGPointMake(self.scrollView.contentOffset.x+frameWidth-self.surfaceMap.frame.origin.x, self.scrollView.contentOffset.y-self.surfaceMap.frame.origin.y);
      NSLog(@"trueLocation (x,y) %.0f,%.0f",trueLocation.x,trueLocation.y);
  
      [self colorOfPixelAtPoint:trueLocation];
  
  }
  </code></pre>
  
  <p>Any input is appreciated!</p>