Iphone uiscrollview and uiimageview - set initial zoom

I use the following code to load an image into a scroll. The image is always loaded with 100% zoom. Is there a way to set it to load at a different zoom level, such as .37?

I tried scrollView.zoomScale = .37 but it didn't 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]; 
+6
objective-c iphone uiscrollview uiimageview zoom
source share
5 answers

I figured this out ... I used scrollView.zoomScale = 0.37; before i uploaded the image, changed the code and it works fine.

 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; 
+11
source share

Scaling works only when implementing the delegate viewForZoomingInScrollView:

 -(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll { return imageView; } 
+18
source share

There is a zoomScale property that you can set.

+3
source share

I ran into the same problem.
I used the built-in method: scrollViewForImage

This will set the initial scaling to level 5.

[self.scrollViewForImage setZoomScale:5 animated:YES];

for minimum zoom level

self.scrollViewForImage.minimumZoomScale=1;

for maximum zoom level

self.scrollViewForImage.maximumZoomScale=12.0;

Hope this helps

+1
source share

You must set the initial scale when viewwillappear, and not when viewdidload works for it too.

0
source share

All Articles