UIScrollView 方向改变时滚动

发布于 2024-10-21 10:29:14 字数 610 浏览 0 评论 0原文

我创建了一个 UIScrollView,在其中放置了一个 UIView。然后我添加一些对象,这些对象是我添加到 UIScrollView 的视图的子视图,以便我可以正确缩放滚动中的所有对象。

关键是我有一个 UIImageView 作为上述视图的子视图,其中包含一个通过使用“imageView.contentMode = UIViewContentModeScaleAspectFit;”适应屏幕尺寸的图像。财产。

最初,在纵向方向上,图像适合屏幕宽度,因此您无法向左或向右滚动。当我将方向更改为横向时,图像适合屏幕顶部和底部。然后是我的问题。您可以上下滚动图像一点点,就好像它保留了纵向的一些顶部和底部填充一样。 但是,如果我尝试缩小,因为我设置的最小缩放为 1,0,图像将恢复其初始大小。那么当缩放比例为1.0时就不能再缩小了。 “虚拟”填充消失了! 似乎它需要某种刷新。 当我不断改变纵向和横向的方向时,也会发生同样的情况。仅当应用程序加载时它才能正常工作。

我尝试设置“myUIScrollView.zoom = 1.0;”在“didRotateFromInterfaceOrientation”方法中(当图像未缩放时)并且它有效,“虚拟”填充再次消失。

看来一旦方向改变就需要刷新。

关于我做错了什么有任何线索吗?

I create a UIScrollView, in which I put a UIView. Then I add some objects which are subviews of the view I added to the UIScrollView, so that I can zoom properly all the objects within the scroll.

The point is that I have an UIImageView as a subview of the mentioned view, which contains an image which is adapted to the screen size by using "imageView.contentMode = UIViewContentModeScaleAspectFit;" property.

Initially, in portrait orientation, the image fits with the screen width, so you can't scroll to left or right. When I change orientation to landscape, image fits with screen top and bottom. Then my problem. You can scroll up and down a little bit the image, as if it preserved some of the top and bottom padding from the portrait orientation.
But, if I try to zoom out, as the min zoom I setted was 1,0, the image recovers its initial size. Then you can't zoom out anymore when the zoom scale is 1.0. The 'virtual' padding is gone!
It seems as if it needed some kind of refresh.
The same happens when I keep changing orientation for portrait and landscape. It only works correctly when app loads.

I tried setting "myUIScrollView.zoom = 1.0;" in "didRotateFromInterfaceOrientation" method (when the image was not zoomed) and it worked, the 'virtual' padding again was gone.

It seems that it needs a refresh once orientation changes.

Any clue about what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文