我有一个图像,我想将其加载到图像视图中,并设置minimumZoomScale,以及将zoomScale设置为aspectFill之类的比例,我计算如下:
// 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 (???)。
但是要让窗口适合 450 像素的空间,这两个数字都不起作用(!!!)。
我手动尝试并发现 0.207 是正确的数字(这将转换为 2174 xp 的图像高度或 406px 的 UIScrollView 高度)。
仅供参考:UIScrollview屏幕为450px,即480px减去状态栏高度(10),减去UITabBar高度(20)
关于这一不当行为有任何线索吗?
不确定你是否还有这个问题,但对我来说,规模完全相反。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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)