滚动时设置 UIScrollView 的 ContentOffset

发布于 2024-10-14 09:49:55 字数 583 浏览 6 评论 0原文

这是我在这里问的第一个问题,请耐心等待


。我已经对此做了很多研究,但未能成功找到有效的解决方案,所以我想我应该把它扔在这里。

我正在使用 UIScrollView 尝试显示一堆 UIImageView。

我在任何时候都有 20 个 UIImageView 加载到滚动视图中。为了显示 20 张以上的照片,我目前所做的就是在每次达到某个 ContentOffset 时让 UIImageViews 更新为新的 UIImages。每当用户向下滚动超过 ContentOffset 95 时,Offset 就会重置为 0 并加载新图片。我选择了一个数字,它给人一种连续滚动的错觉,因此用户看不到视图的重新加载/重置。当您向上滚动超过 0 时,也会发生同样的事情。

我的问题是,当您轻弹 UIScrollView (以便它继续自行滚动)时,ContentOffset 似乎没有像预期的那样重置。视图本身正在正确重置,对于 1 次迭代,偏移量为 0,但在下一次迭代(一瞬间之后)中,偏移量上升到 120 或 130,并且它会向下跳跃,就好像我已经到达下一个迭代的末尾一样屏幕。

任何人都知道如何在 UIScrollView 滚动时正确重置 ContentOffset ?

This is the first question I have asked here so bear with me


. I've done quite a bit of looking into this but have been unsuccessful in finding a solution that worked so I figured I'd toss it out here.

I am using a UIScrollView to try and display a bunch of UIImageViews.

I have 20 UIImageViews loaded into the Scroll View at any one time. What I'm doing at the moment to show more than just 20 photo's is to have the UIImageViews update with new UIImages every time a certain ContentOffset it reached. Whenever the user scrolls down past a ContentOffset of 95 the Offset is reset to 0 and the new pictures are loaded. I picked a number that gave the illusion of continual scrolling so the user does not see the reloading/resetting of the view. The same thing happens when you scroll upwards past 0.

My problem is that when you flick the UIScrollView (so that it continues to scroll by itself) it seems as if the ContentOffset is not resetting like it's supposed to be. The view itself is resetting properly and for 1 iteration the offset is 0, but in the next iteration ( a split second later ) the offset is up in the 120's or 130's and it's jumping down as if I've reached the end of the next screen.

Anyone have any idea how to properly reset the ContentOffset while the UIScrollView is scrolling?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界如花海般美丽 2024-10-21 09:49:55

显然惯性算法与您正在做的事情不兼容。为什么不让它自由滚动,而是回收在可见矩形之外滚动的图像视图,以获取另一侧出现的图像视图? (就像桌面视图一样)

Apparently the inertia algorithm isn't compatible with what you're doing. Why not let it scroll freely and instead recycle the Imageviews that scroll outside of the visible rect for the ones that appear at the other side? (just like a tableview works)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文