是否可以知道图像是否在 iPhone 系统缓存中?
我正在尝试提高 UITableView 的滚动性能。我使用 imageNamed: 和dispatch_async 加载图像,但是一旦图像加载到单元格中,滚动效果就非常好。我只想在图像不在系统缓存中时淡入图像,以减少图像“弹出”到视图中的刺耳效果。
有没有办法知道图像是否已经在系统缓存中?
I am trying to improve scrolling performance of a UITableView. I am loading the images using imageNamed: and dispatch_async, but scrolling is very good once the images have been loaded into the cells. I would like to fade in the images only if they are not in the system cache to reduce the jarring effect of the images "popping" into view.
Is there a way to know if an image is already in the system cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有记录的方法可以查看 UIImage 内部来检查此类内容。
我认为确定图像立即可用的唯一方法是强制加载 UIImage。这可以在后台完成,方法是使用 CGImage 函数创建 UIImage 并访问它的像素。如果您确保不需要重新缩放(即不要将 3000x2000 的图像放置在 30x20 的空间中),那么它应该可以正常显示。
There is no documented way to look inside the UIImage to check such things.
I think the only way to know for sure that the image is available immediately, is to force the UIImage to be loaded. This can be done in the background, by creating the UIImage and accessing it's pixels, using CGImage functions. If you ensure that there is no rescaling needed (i.e. don't put a 3000x2000 image in a 30x20 space) then it should display without a glitch.