是的,Photos.app 正在缓存较低分辨率的图像。好消息是您也可以获得这些缓存版本。您可能已经知道 ALAssetRepresentation 的 fullScreenImage 属性和 ALAsset 的 thumbnail 属性。那些应该更快加载。
我发现高分辨率图像只是加载它可能需要 1-2 秒,所以我猜只是在背景中加载高分辨率图像可能会为你解决问题。
那么,如何加载图像的低分辨率版本,然后在有 i 时切换到高分辨率版本?它可能有点复杂,但希望这能让你开始。由于您使用的是 AssetsLibrary,因此您将不得不使用 iOS 4,这是个好消息,因为您可以使用块和 GCD/libdispatch 轻松完成此操作。很高兴您正在观看 WWDC 视频——请查看第 206 和 211 场会议,了解有关 GCD 的大量重要信息。
基本思想是,您将在主线程上显示较低分辨率的版本,然后让后台线程加载全分辨率图像,然后告诉 CATiledLayer 切换到全分辨率图像。
- (void)displayAsset:(ALAssetRepresentation *)asset {
UIImage *lowresImage = [UIImage imageWithCGImage:asset.fullScreenImage
orientation:asset.orientation scale:asset.scale];
// Add code here to display the lowresImage
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^ {
// Load the full resolution image from the asset
UIImage *highresImage = [UIImage imageWithCGImage:asset.fullResolutionImage
orientation:asset.orientation
scale:asset.scale];
// Once done, tell the main thread to display the tiles
dispatch_async( dispatch_get_main_queue(),
^ {
// Code to swap out the lowresImage for highresImage
});
});
}