2010-10-06 53 views
6

我有要装载到图像视图和minimumZoomScale,以及所述zoomScale设置为aspectFill形标尺我计算如下图像:计算一个UIScrollView的minimumZoomScale

// 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; 

的iScrollView大小为450 x 320像素,iImageSize为1600 x 1960像素。

手动操作minimumZoomScale数学公式:450/1960 = 0.22959184。 系统确定0.234693885,而不是(???)。

但为了让窗口适合450px空间,两个数字都不起作用(!!!)。 我手动尝试,发现0.207是正确的数字(这将转化为图像高度2174 xp或者UIScrollView高度406px)。

的信息:在UIScrollView的屏幕为450像素,即480像素减去状态栏的高度(10),减去UITabBar高度(20)

这一不当行为任何线索?

+0

我遇到这一点。我将minimumZoomScale设置为某个值,然后在某个点自动调整。虽然这个调整或多或少都不明显,但我只是将其留在了,并且之后添加了这一行scrollview.zoomScale = scrollview.minimumZoomScale;只是为了确保一切都同步。 – Altealice 2010-10-06 11:16:31

回答

0

对于简单的放大/缩小我一般使用下面的代码。 minimumZoomScale = 1将初始缩放设置为当前图像大小。我已经给出了最大缩放比例= 10,它可以根据图像大小和容器帧大小的实际比率来计算。

[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]; 
0

不知道你是否仍然有这个问题,但对于我来说,规模恰恰相反。 minimumZoomScale = 1对我来说,我必须计算maximumZoomScale

下面的代码:

[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;