OGeek|极客世界-中国程序员成长平台

标题: ios - 无法在 UIScrollView 和 AutoLayout 中使用 AspectFill 滚动 UIImageView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:57
标题: ios - 无法在 UIScrollView 和 AutoLayout 中使用 AspectFill 滚动 UIImageView

我有一个带有单个 UIImageView 子的 UIScrollView。 ScrollView 通过自动布局固定在(根)父容器的所有侧面,并且子 ImageView 也固定在内容模式设置为 AspectFill 的所有侧面。

UIImage *image = [UIImage imageNamed"photo1.jpeg"];

_imageView.image = image;
_imageView.contentMode = UIViewContentModeScaleAspectFill;

_scrollView.contentOffset = CGPointZero;
_scrollView.contentSize = _imageView.image.size;
_scrollView.zoomScale = 1;

这种情况下的图像比我的屏幕宽。当我启动我的应用程序时,imageview 正确显示了填满屏幕的图像。但是,我似乎无法向左或向右平移图像。当我放大时,我可以平移,但是,我无法平移到图像的角落。

由于自动布局,我觉得我的内容大小没有被正确计算,但我不确定我可以播放哪些参数来让我将图像滚动到边缘。

我在下面附上了一张图片,您可以在其中看到图片无法以显示“幸福”开头的方式滚动。我还上传了样本 here

autolayout



Best Answer-推荐答案


the child imageview is also pinned to all sides

相反,为子 ImageView 关闭自动布局(将其 translates... 设置为 YES)。您已经将 ScrollView 的 contentSize 设置为图像大小,因此现在可滚动性将跃然纸上,并与缩放正确交互。

关于ios - 无法在 UIScrollView 和 AutoLayout 中使用 AspectFill 滚动 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31296497/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4