【发布时间】:2012-02-14 09:32:28
【问题描述】:
我有一个有趣的问题。我有一个 UIScrollView 并且里面只有一个带有图像的 UIImageView。我需要这个来进行缩放和平移。 行。在按钮触摸时,我想将 UIImageView 中的图像(如前所述,在 UIScrollView 中)替换为下一个。
到目前为止,我已经这样做了:
self.imageView = nil;
self.imageView = [[UIImageView alloc] initWithImage:nextImage];
我总是将self.imageView 设置为 nil 的原因是,如果我不这样做,下一张图像就会像上一张一样缩放或缩放。
但我认为这不是提高内存效率的好解决方案。
还有其他方法可以在 UIImageView 上设置新图像,并使用“重置”选项进行缩放、缩放等...?
更新: 还是不行的代码:
[self.scrollView setZoomScale:1.0];
[self.imageView setImage:photoImage];
[self.imageView setFrame:rect];
[self.scrollView setContentSize:[self.imageView frame].size];
CGFloat minZoomScale = [self.scrollView frame].size.width / [self.imageView frame].size.width;
if (minZoomScale < [self.scrollView frame].size.height / [self.imageView frame].size.height) {
minZoomScale = [self.scrollView frame].size.height / [self.imageView frame].size.height;
}
[self.scrollView setMinimumZoomScale:minZoomScale];
[self.scrollView setZoomScale:[self.scrollView minimumZoomScale]];
更新 2 刚刚弄清楚我做错了什么。我没有重置最小缩放比例。
[self.scrollView setMinimumZoomScale:1.0];
现在可以了!
【问题讨论】:
标签: ios uiscrollview replace uiimageview uiimage