title: UIImageView in UIScrollView: panning fail
body: <p>I am making a simple photo viewer that allows zooming and panning.</p>
  
  <p>so in IB I create a UIScrollView containing a UIImageView:</p>
  
  <p><img src="https://i.stack.imgur.com/6HjW2.png" alt="enter image description here"></p>
  
  <p>Then I can configure it to house the photo as soon as the photo is available:</p>
  
  <pre><code>- (void) imageCaptureCompleted 
  {
      {
          UIImage* I = self.frontCamView.stillImage;
  
          self.imageView.bounds = CGRectMake(0, 0, I.size.width, I.size.height );
          self.imageView.image = I;
  
          // - - - 
  
          self.scrollView.maximumZoomScale = 4.0;
          self.scrollView.minimumZoomScale = 0.75;
          self.scrollView.clipsToBounds = YES;
          self.scrollView.delegate = self;
  
          self.scrollView.contentSize = self.imageView.bounds.size;
      }
  
      [self hideCaptureView];
  
      UIImageWriteToSavedPhotosAlbum( self.frontCamView.stillImage, 
                                     self, 
                                     @selector( image: didFinishSavingWithError: contextInfo: ), 
                                     nil );
  }
  
  - (UIView *) viewForZoomingInScrollView: (UIScrollView *) scrollView
  {
      return self.imageView;
  }
  </code></pre>
  
  <p>This is almost working. It is indeed letting me pan and zoom.</p>
  
  <p>However, it pans too far! It should bounce back when it hits the right edge of the photo.   but instead it behaves as if the photo is in a larger black rectangle.</p>
  
  <p>I have set up the autoresizing masks of the scroll view in exactly the same way as per the  above picture.</p>
  
  <p>How to get it to work?</p>
  
  <p>PS I have now figured this out; I will put up the answer for posterity.</p>