I am making a simple photo viewer that allows zooming and panning.
so in IB I create a UIScrollView containing a UIImageView:

Then I can configure it to house the photo as soon as the photo is available:
- (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;
}
This is almost working. It is indeed letting me pan and zoom.
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.
I have set up the autoresizing masks of the scroll view in exactly the same way as per the above picture.
How to get it to work?
PS I have now figured this out; I will put up the answer for posterity.