将图像加载到 UIImageView 时 UIScrollView 挂起
我有一个启用了分页的 UIScrollView 。所有图像都在开始时加载并添加到 UIImageViews 中,但我遇到了内存问题,因为它有更多图像,所以我决定在滚动时加载下一个图像(如果图像尚未设置)。如果我收到内存警告,我会删除除当前图像之外的所有图像。
问题是,如果我滚动,滚动视图会挂起几毫秒。
我用来
UIImage *image = [UIImage imageNamed:@"path/to/image.png"];
加载图像。如果我使用 imageWithContentsOfFile 方法,则会花费更多时间。
有没有办法像默认的照片应用程序一样显示像素化图像,直到它完全加载?
感谢您提前的答复。
I have a UIScrollView with paging enabled. All the images were loaded at the start and added to the UIImageViews, but I had a memory-issue as it were more images, so I decided to load the after next image while scrolling if the image isn't set yet. If i get a memory warning, I remove all images except of the current.
The problem is, that the scrollview hangs for a few milliseconds if I scroll.
I'm using
UIImage *image = [UIImage imageNamed:@"path/to/image.png"];
to load the images. If I use the method imageWithContentsOfFile, it cost alot more time.
Is there a way to show a pixelated image like in the default Photoapp until it's fully loaded?
Thanks for your answers in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为您缓存图像,这就是它比 imageWithContentsOfFile 更好的原因。由于这些图像显示在表格单元格中,因此它们可能不需要那么大。文件系统上的图像尺寸是多少?如果您只是将 UIImage 放入 UIImageView 中并依赖它进行缩放,我的猜测是缩放是在您滚动时发生的。您可以为文件系统上的每个图像创建缩略图并使用它们吗?
caches images for you, so that's why it's better than imageWithContentsOfFile. Since these images are displayed in a table cell, presumably they don't need to be that large. What are the images dimensions on the file system? If you just put the UIImage in a UIImageView and depend on that for scaling, my guess is the scaling happens while you scroll. Can you create thumbnails for each image on the file system and use those?