0
votes

I am making a simple photo viewer that allows zooming and panning.

so in IB I create a UIScrollView containing a UIImageView:

enter image description here

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.

1

1 Answers

0
votes

This code sorts it out:

        // self.imageView.bounds = CGRectMake(0, 0, I.size.width, I.size.height );
        self.imageView.image = I;

        [self.imageView sizeToFit];

However, I can't understand why this change is necessary. If anyone can tell me, I will accept that answer ( in which case please paste the above code then I can remove this answer ).