title: UIScrollView odd behavior: zoom in, pan, zoom out leaves content view uncentered
body: <p>I have a custom UIViewController subclass controlling a UISCrollView containing an UIImageView, set up like so:</p>
  
  <pre><code>UIViewController
  + UIScrollView (delegate: UIViewController, viewForZoomingInView: UIImageView)
    + UIImageView
  </code></pre>
  
  <p>I can use the UIScrollView to zoom in on my image, and pan around -- but if I do so such that the center of the view is not the center of the image, and then zoom out fully, my image is off center; what's more, since I am at the minimum zoom scale at that point, I cannot pan around to re-center my image.</p>
  
  <p>My expectation was that when zooming out, UIScrollView would re-center the contentSize's area under its bounds so that you never see beyond the edge of the content view (or rather, the content view's size plus contentInset). Am I wrong in this assumption?</p>
  
  <p>If so, what should I do to provide this behavior?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      imageView.image = image;
      [imageView sizeToFit];
  
      float minimumScale = [imageScrollView frame].size.width  / [imageView frame].size.width;
  
      imageScrollView.contentSize = [imageView frame].size;    
      imageScrollView.maximumZoomScale = 2.0;
      imageScrollView.minimumZoomScale = minimumScale;
  
      imageScrollView.zoomScale = imageScrollView.minimumZoomScale;
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      return YES;
  }
  
  - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  {
      return imageView;
  }
  
  - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
  {
      // nothing
  }
  </code></pre>
  
  <p><strong>EDIT: Solution!</strong></p>
  
  <p>You have to set <code>clipsToBounds = YES</code> on the UIScrollView to get the desired behavior. I didn't find this initially because it is a property of UIView, not of UIScrollView directly.</p>