ScrollView 作为 PhotoViewer,仅在需要时加载图像
我想为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
怎么样做一个 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.
您看过 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!