ScrollView 作为 PhotoViewer,仅在需要时加载图像

发布于 2024-10-26 04:51:47 字数 342 浏览 2 评论 0原文

我想为 iPhone 创建一个 PhotoViewer。

为此,我已经创建了一个启用了分页的 ScrollView,其中我以编程方式添加了 UIImageViews。我看到的问题是,如果我有 100 个图像并且全部添加到 ScrollView 中,那么将占用大量性能和内存。

您将如何使其性能更高?我想过在滚动页面时加载以下2页的图像并释放之前2页图像之后的图像。

我考虑创建 UIScrollView 的子类并将其命名为 UIPhotoScroller (或类似的名称)。但我还想在主窗口中显示 UIView 以及有关图像的信息。是否可以使 UIView 从子类中可见?

你真的会帮助我的。预先感谢您:D

I would like to create a PhotoViewer for an iPhone.

For that, I already created a ScrollView with Paging enabled in that I add programmically add the UIImageViews. The problem I see is, that if I would have like 100 Images and I would all add to the ScrollView it would take alot of performance and memory.

How would you make it more performant? I thought about loading the Images of the following 2 pages and releasing the Images after the 2 Images before when scrolling through the pages.

I thought about creating a Subclass of UIScrollView and to name it UIPhotoScroller (or something like that). But I also want to show a UIView in the MainWindow with Information about the Images. Is it possible to make the UIView visible from the Subclass?

You really would help me with that. Thank you in advance :D

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

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

发布评论

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

评论(3

煮酒 2024-11-02 04:51:47
  1. 创建一个 NSCache。
  2. 当您需要特定图像时,请尝试从缓存中获取它。如果不存在,请从磁盘加载它并将其保存在缓存中。文件名是合适的键。
  3. 当您收到内存警告时,请告诉缓存自行清空。
  4. 缓存将定期释放其一些条目,具体取决于其配置方式。这是一件好事,但您可能需要调整它以获得特定的总内存大小。调整它的参数,直到它的行为符合您的要求。要查看内存使用情况,请使用 Instruments。
  1. Create an NSCache.
  2. When you need a particular image, try to get it from the cache. If it's not there, load it from disk and save it in the cache. The filename is a suitable key.
  3. When you get a memory warning, tell the cache to empty itself.
  4. The cache will release some of its entries periodically, depending on how it's configured. This is a good thing, but you might want to adjust it to have a particular total memory size. Tweak its parameters until it behaves like you want it to. To see your memory usage, use Instruments.
十二 2024-11-02 04:51:47

怎么样做一个 UITableView 每个单元格一张照片。当数据源请求单元格时,您会显示一个微调器,并让排队的 NSOperation 加载图像并在完成后刷新行。
您可以使用 NSQueue 控制并发操作的数量,因此您可以完全控制性能/响应能力。然后,您可以在内存/分页不足等情况下删除旧的缓存图像。

如果您需要水平滚动。

How about doing a UITableView with a single photo per cell. When a cell is being request by the data source, you display a spinner and have a queued NSOperation load the image and refresh the row when done.
You can control the amount of concurrent ops with a NSQueue, so you have complete control on performace/responsiveness. You can then remove old cached images when low on memory/paging, etc.

There are solutions to horizontal UITableView if you need horizontal scrolling.

穿越时光隧道 2024-11-02 04:51:47

您看过 Three20 库 吗?有一个创建类似照片应用程序的出色照片查看器的示例,并且使用 Three20 库非常容易。

希望这有帮助!

Have you looked at the three20 library? There's an example of creating a great Photos app-like viewer of photos, and it's pretty easy to work with the three20 library.

Hope this helps!

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