title: Setting UIScrollView's origin for pinch gestures
body: <p>I'm creating a scroll view for displaying a very large view, and I need both scroll and zoom functionality (just like an image viewer). Here are the steps that I've taken:</p>
  
  <ol>
  <li>In interface builder, I've put a scroll viewer to the view controller.</li>
  <li>I've added a pinch gesture recognizer to the scroll viewer.</li>
  <li>I've connected the gesture recognizer's action to the code to handle the gesture events.</li>
  <li>When the view controller is loaded, I change my view's origin to the center (<code>viewer</code> is my scroll viewer): <code>self.viewer.contentOffset = CGPointMake(384, 512);</code></li>
  <li>In my code for the handler, I handled the event as such:</li>
  </ol>
  
  <p>(<code>startScale</code> is 1.0 in the beginning)</p>
  
  <pre><code>- (IBAction)handlePinch:(UIPinchGestureRecognizer *)sender {
      if(sender.state == UIGestureRecognizerStateEnded){
          startScale *= sender.scale;
      }else{
          float result = sender.scale * startScale;
  
          self.viewer.transform = CGAffineTransformMakeScale(result, result);
      }
  }
  </code></pre>
  
  <p>When I run the app, the gesture is recognized and scaling works correctly, however, the whole view scales with respect to the <code>0,0</code> point of the screen (top left). I want it to scale with respect to the middle point that I'm applying the gesture, just as a natural pinch gesture for zooming into a photo.</p>
  
  <p>I've also tried setting <code>self.viewer.frame</code>'s origin, but nothing changed. I've searched about the problem and found these:</p>
  
  <p><a href="https://stackoverflow.com/questions/10012406/how-to-set-a-uiviews-origin-reference">How to set a UIView&#39;s origin reference?</a> (already tried)</p>
  
  <p><a href="https://stackoverflow.com/questions/13163279/pinch-punch-gestures-center">https://stackoverflow.com/questions/13163279/pinch-punch-gestures-center</a> (about my problem, but unanswered)</p>
  
  <p><a href="https://stackoverflow.com/questions/9954582/uipinchgesturerecognizer-for-zooming-and-panning-an-image-in-xcode">UIPinchGestureRecognizer for zooming and panning an image in xcode</a> (looks like an overkill, too complicated for me, and I'm not sure if this would really help my situation)</p>
  
  <p>How can I achieve natural pinching with my scroll view, what am I doing wrong?</p>
  
  <p>Thanks,
  Can.</p>