views:

1010

answers:

3

I use the following code to load an image into an scroll view. The image always loads at 100% zoom. Is there a way to set it to load to another zoom level, say .37?

I have tried scrollView.zoomScale = .37 but it didnt seem to work

UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
        self.imageView = tempImage;

        scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
        scrollView.maximumZoomScale = 1;
        scrollView.minimumZoomScale = .37;
        scrollView.clipsToBounds = YES;
        scrollView.delegate = self;

        [scrollView addSubview:imageView];
+1  A: 

There is a zoomScale property that you can set.

KennyTM
But take note that as Brodie4598 mentioned that this should be done after the imageView has been added to the scrollView.
paul_sns
+2  A: 

Zooming only works when you implement the viewForZoomingInScrollView: delegate callback.

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
  return imageView;
}
drawnonward
I did not know this and it solved my problem. Thanks so much!
K-RAN
A: 

I figured it out... I was using scrollView.zoomScale = 0.37; before I loaded the image changed code and it works great.

UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
self.imageView = tempImage;

scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 1;
scrollView.minimumZoomScale = .37;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
scrollView.zoomScale = .37;
Brodie