UIScrollView 的内容大小

时间:2022-12-31
本文介绍了UIScrollView 的内容大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 UIScrollView,我在其中将 contentSize 设置为最初的屏幕大小.那么这是否意味着如果我在滚动视图中有一个 UIImageView 那么它不能放大到大于我设置的 contentSize ?

I have a UIScrollView in which I've set the contentSize to the size of the screen initially. So does this mean that if I have an UIImageView inside the scroll view then it can't zoom bigger than the contentSize I've set?

因为我最初有一个 UIScrollView 和手机尺寸的 contentSize 并且当我放大图像时,它做得很好(我可以看到 contentSize 随着我放大而变大)但是当我手动调整它时它不能.这是为什么呢?

Because I initially have a UIScrollView with a contentSize of the phone's dimension and when I zoom into an image, it does it just fine (I can see the contentSize grows bigger as I zoom in) but when I adjust it manually it can't. Why is this?

我认为当我最初初始化 UIScrollView 框架时,内容大小将设置为框架的大小,但是当我放大时它可以动态增长.但是当我尝试设置 contentSize,现在好像已经修复了.我问这个的原因是因为我在 UIScrollView 中有一个 UIImageView,当我放大图像并旋转图像时,我想要 contentSize 重置.问题是如何重置?

I think when I initially initialize the UIScrollView frame, the content size will be set to the frame's size, however it can grow dynamically as I zoom in. However when I try to set the contentSize, it seems that now it's fixed. The reason why I am asking this is because I have a UIImageView inside a UIScrollView, when I zoom in on the image and I rotate the image, I want the contentSize to reset. Question is how do I reset this?

推荐答案

缩放级别由 UIScrollViewzoomScale 属性设置.其最大值和最小值分别由 maximumZoomScaleminimumZoomScale 设置.

The zoom level is set by the zoomScale property of the UIScrollView. Its maximum and minimum is set by maximumZoomScale and minimumZoomScale respectively.

如果您尝试通过设置 contentSize 来设置缩放,那么您做错了.contentSize 应该设置为好像缩放比例是 1.0 然后你只需将 zoomScale 属性设置为你想要的例如 2.0 如果你想放大到 200%.

If you're trying to set the zoom by setting the contentSize then you're doing it wrong. The contentSize should be set as if the zoom scale was 1.0 and then you'd just set the zoomScale property to be what you wanted so for example 2.0 if you wanted it zoomed in to 200%.

您可能会在缩放时看到 contentSize 发生变化,因为我认为滚动视图报告它已缩放到当前缩放比例.

You're probably seeing contentSize change as you zoom because I think the scroll view reports it scaled to the current zoom scale.

这篇关于UIScrollView 的内容大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:滚动视图不在 xib 文件中滚动 下一篇:UIScrollView 无限滚动?

相关文章

最新文章