title: Zooming UIImageView in UIScrollView goes out of bounds
body: <p>I've successfully implemented zooming of <code>UIImageView</code> in my <code>UIScrollView</code> but I have faced with a strange problem that irritates me.</p>
  
  <p>Basically, when I zoom in the image</p>
  
  <p><img src="https://i.stack.imgur.com/iFe5V.png" alt="enter image description here"></p>
  
  <p>I can pan the view to actually scroll out of the image border and I'm left with a black area like this:
  <img src="https://i.stack.imgur.com/1flbn.png" alt="enter image description here"></p>
  
  <p>And as I zoom in more I can make the black border to fill the whole screen!
  Meanwhile in the iPhone Photo app you can't zoom out the actual image. What's wrong here in my implementation?</p>
  
  <p>It looks like this:</p>
  
  <pre><code>UIImage *imageToDisplay = [UIImage imageWithData:tmpImageData];
  imageViewMain.image = imageToDisplay;
  imageViewMain.frame = CGRectMake(0, 0, scrollViewMain.frame.size.width, scrollViewMain.frame.size.height);
  imageViewMain.contentMode = UIViewContentModeScaleAspectFit;
  
  scrollViewMain.delegate = self;
  scrollViewMain.minimumZoomScale = 1.0;
  scrollViewMain.maximumZoomScale = 9.0;
  scrollViewMain.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  scrollViewMain.contentSize = imageViewMain.frame.size;
  
  [self.view addSubview:scrollViewMain];
  [scrollViewMain addSubview:imageViewMain];
  </code></pre>
  
  <p>And I also implement this method:</p>
  
  <pre><code>- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
  {
      return imageViewMain;
  }
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:
  When I first load the view I shrink my UIImageView to fit the scroll view and the image looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/DWhFm.png" alt="enter image description here"></p>