gpt4 book ai didi

iphone - 计算 UIScrollView 的 minimumZoomScale

转载 作者:太空狗 更新时间:2023-10-30 03:46:03 25 4
gpt4 key购买 nike

我有一个图像,我想将其加载到 ImageView 中,并将 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;

关于iphone - 计算 UIScrollView 的 minimumZoomScale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3869779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com