ZoomScale UIScrollView Minimum Calculation

I have an image that I want to load into the image view and set the minimum ZoomScale value as well as the zoom scale to the scalable aspectFill value, which I calculate as follows:

// configure the map image scroll view iImageSize = CGSizeMake(iImageView.bounds.size.width, iImageView.bounds.size.height); iScrollView.minimumZoomScale = iScrollView.bounds.size.height / iImageSize.height; iScrollView.maximumZoomScale = 2; iScrollView.zoomScale = iScrollView.minimumZoomScale; iScrollView.contentOffset = CGPointMake(0, 0); iScrollView.clipsToBounds = YES; 

The iScrollView is 450 x 320 pixels in size and the iImageSize is 1600 x 1960 pixels.

Performing the MinimumZoomScale math manually: 450/1960 = 0.22959184. Instead, the system determines 0.234693885 (???).

But for the window to fit into the space of 450 pixels, both shapes do not work (!!!). I manually tried and found 0.207 - this is the correct number (which will translate to an image height of 2174 xp or, alternatively, a UIScrollView height of 406px).

For information: the UIScrollview screen is 450 pixels, namely 480px minus the height of the status bar (10), minus the height of the UITabBar (20)

Any clues about this abnormal behavior?

+6
objective-c iphone xcode
source share
2 answers

Not sure if you still have this problem, but for me the scale is exactly the opposite. minimumZoomScale = 1 for me, and I have to calculate maximumZoomScale .

Here is the code:

 [self.imageView setImage:image]; // Makes the content size the same size as the imageView size. // Since the image size and the scroll view size should be the same, the scroll view shouldn't scroll, only bounce. self.scrollView.contentSize = self.imageView.frame.size; // despite what tutorials say, the scale actually goes from one (image sized to fit screen) to max (image at actual resolution) CGRect scrollViewFrame = self.scrollView.frame; CGFloat minScale = 1; // max is calculated by finding the max ratio factor of the image size to the scroll view size (which will change based on the device) CGFloat scaleWidth = image.size.width / scrollViewFrame.size.width; CGFloat scaleHeight = image.size.height / scrollViewFrame.size.height; self.scrollView.maximumZoomScale = MAX(scaleWidth, scaleHeight); self.scrollView.minimumZoomScale = minScale; // ensure we are zoomed out fully self.scrollView.zoomScale = minScale; 
0
source share

For easy zooming in / out, I usually use the code below. minimumZoomScale = 1 sets the initial zoom to the current image size. I gave maximumZoomScale = 10, which can be calculated from the actual ratio of image size and container frame size.

 [scrollView addSubview: iImageView]; scrollView.contentSize = iImageView.frame.size; scrollView.minimumZoomScale = 1.0; scrollView.maximumZoomScale = 10; [iImageView setFrame:CGRectMake(0, 0, 450, 320)]; [scrollView scrollRectToVisible:iImageView.frame animated:YES]; 
-one
source share

All Articles