UIScrollView 问题...加载图像

发布于 2024-11-09 07:44:54 字数 503 浏览 0 评论 0原文

我有一个不进行分页的 UIScrollView。我正在加载大约 500 张小图像(64x64-iPhone 192x192-iPad)。我不想将它们全部加载到内存中。我想在用户滚动时加载它们。

谁能告诉我在哪里可以设置要显示的图像?我为每个图像都有一个对象,其中包含图像资源名称、索引号以及应在 UIScrollView 中显示的 x 和 y 坐标。我希望有一种方法可以重写,我可以在其中创建 UIImageView,然后将视图添加到动态滚动视图中......也许一次预加载 6 到 10 个图像。我看到的每个示例都使用分页,并且一次仅显示一张图像。

非常感谢任何帮助或示例。

谢谢

编辑:

在 Apple 的 ScrollViewSuite 示例中,有一个平铺示例。该示例有一个滚动视图,会弹出显示可供选择的图像。这正是我想做的,但我需要动态加载它们。该示例将所有缩略图加载到内存中。一定有人在这样做,因为 iPod/iPhone 和 iPad 没有足够的内存来加载所有图像。

I have a UIScrollView that does not do paging. I am loading about 500 small (64x64-iPhone 192x192-iPad) images. I do not want to load them all into memory. I would like to load them as the user scrolls.

Can anyone tell me where I can set the images to display? I have an object for each image that holds the image resource name, index number and x and y coordinate where it should be displayed in the UIScrollView. I was hoping there was a method I could override where I could create a UIImageView and then add the view to the scroll view on the fly... maybe preloading 6 to 10 images at a time. Every sample I see uses paging and only displays one image at a time.

Any help or example is greatly appreciated.

Thank you

EDIT:

In the ScrollViewSuite examples from Apple there is a Tiling example. That example has a scrollview that popups up displays images to select from. That is exactly what I am trying to do, but Ineed to load them on the fly. The sample loads all of the thumbnail images into memory. Someone somewhere must be doing this because the iPod/iPhone and iPad do not have alot of memory to load all the images.

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

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

发布评论

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

评论(4

转瞬即逝 2024-11-16 07:44:54

苹果有一些非常好的演示代码来展示如何做到这一点。查看 TiledScrollView.m 特别是layoutSubviews方法。

Apple has some really good demo code that shows how to do this. Check out TiledScrollView.m especially the layoutSubviews method.

披肩女神 2024-11-16 07:44:54

在scrollview的以下方法中编写代码:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

我也是这样做的。在开始时至少加载一些图像,然后在上述方法中加载这些图像。

正确分配和释放图像视图,因为它们可能导致内存泄漏

希望这对您有用:)
干杯:)

write the code in following method of scrollview:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

I did the same. Load atleast few images in the beginning and then load those images in above method.

PROPERLY ALLOC AND RELEASE IMAGEVIEWS SINCE THEY CAN LEAD TO MEMORY LEAKS

Hope this works for you :)
Cheers :)

自此以后,行同陌路 2024-11-16 07:44:54

难道你不能只使用 UITableView 来实现这个吗?

编辑:可能值得一看

Couldn't you just use a UITableView for this?

Edit: Might be worth looking at

浴红衣 2024-11-16 07:44:54

你可以尝试使用 CAAffinneTransform 使你的表格视图水平,并将角度指定为(3.14/2),即 90 度,并且可以有一个带有水平滚动的水平表格视图,并且可以使用 MIKE A 给出的上述参考
问候...

u can try making ur tableview horizontal by using CAAffinneTransform and giving the angle as (3.14/2) ie 90 degree annd can have a horizontal tableview with horizontal scroll and can use the above refrence given by MIKE A
regards...

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