2 UIScrollView检测当前页面并加载正确的页面

发布于 2024-09-27 00:15:37 字数 784 浏览 5 评论 0原文

问题的第一部分:检测滚动视图 A 和 B 中显示的当前图像

我想在主视图中放置两个 UIScrollView。非常简单地完成了。所以我把 UIScrollView A 放在 UIScrollView B 上面。 所以它看起来像这样:

Graphical representation
________
|  A   |   ScrollViewA is above ScrollViewB  
|______|
|  B   |   ScrollViewB is below ScrollViewA
|______|

用户可以在两个 ScrollView 上左右滑动图像。 它们都显示不同的图像集。

首先我想知道如何检测两个滚动视图所在的图像。对于A和B。

所以我应该能够检测哪些图像正在scrollviewA和scrollview B上显示 例如:UIScrollView A 在图像 12 上,UIScrollView B 在图像 67 上。

问题的第二部分:当用户从左和右滚动时在两个滚动视图上加载图像

因为 ScrollViewA 中会有很多图像用户可以从左向右滚动; ScrollViewB 中的许多图像用户也可以从左向右滚动;显然我不想将它们全部加载到滚动视图中。我可以在滚动视图中加载它们的最佳方式是什么?

一个想法是,如果用户在图像 5 上,那么用户向左滑动,那么下一个图像将是 6,因此仅加载该图像。等等。

每个人都可以帮助我如何实现这样的事情吗?谢谢。 您的所有想法和帮助将不胜感激。

First part of the question: Detecting current images being displayed in scrollview A and B

i want to place two UIScrollViews in my main view. Very simply done. So ive placed UIScrollView A above UIScrollView B.
so it looks like this:

Graphical representation
________
|  A   |   ScrollViewA is above ScrollViewB  
|______|
|  B   |   ScrollViewB is below ScrollViewA
|______|

There will be images which the user can flick through left and right on both ScrollViews.
They both show different set of images.

First i want to know how to detect which image the both scrollviews are on. for both A and B.

so i should be able to detect which images are being displayed on scrollviewA and scrollview B
eg: UIScrollView A is on image 12 and UIScrollView B is on image 67.

Second part of the question: Loading images on both scroll view as user scrolls from left and right

Because there will be many images in ScrollViewA that the user can scroll from left to and right; and many images in ScrollViewB that the user can also scroll from left to right; obviously i dont want to load them all into the scroll view. Whats the best way i can load them in a scrollview?

an idea is if a user is on image 5, then the user flicks to the left, then the next image will be 6 so only load that image. and so on.

Can everyone help me on how to implement such a thing. Thank you.
All your ideas and help will be appreciated.

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

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

发布评论

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

评论(1

﹎☆浅夏丿初晴 2024-10-04 00:15:37

加载图像时,您可以执行以下操作:

  1. 加载当前图像
  2. 缓冲加载下一张和上一张图像,并将它们放置在可见视图的边界之外
  3. 当用户向左滑动时,将右图像移动到视图中,卸载左图像并缓冲新的右图像。对正确的人做同样的事情。

这样,滚动视图一次只会加载 3 个。

在跟踪加载了哪个图像时,您必须自己跟踪它。

On loading images, you can do this:

  1. Load current image
  2. Buffer load next and previous images and position them outside the bounds of the visible view
  3. When user flicks left, move right image into view, unload the left image and buffer a new right image. Do the same thing for the right one.

This way you will only have 3 loaded at a time for a scrollview.

On keeping track of which image is loaded, you have to keep track of that yourself.

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