gpt4 book ai didi

ios - 照片框架 : UICollectionView scrolling jitter

转载 作者:行者123 更新时间:2023-11-29 12:10:33 24 4
gpt4 key购买 nike

我正在使用 Photos 框架和 requestImageForAsset: 花费太多时间,因此它的滚动性能确实很差。

我尝试将 PHImageRequestOptions 选项设置为:

let options: PHImageRequestOptions = PHImageRequestOptions()
options.deliveryMode = PHImageRequestOptionsDeliveryMode.FastFormat

滚动变得完全平滑(所以我知道这是唯一的原因)但是对于 FastFormat 交付选项,缩略图仍然模糊,resultHandler: 将只调用一次,图像质量下降。

目前我正在使用以下代码(滚动效果不佳):

    // Size is proper as per scale i.e(ui-width * scale, uiheight * scale)
self.imageManager?.requestImageForAsset(phAsset,
targetSize: size,
contentMode: PHImageContentMode.AspectFill,
options: nil,
resultHandler: { (resultImage, info) -> Void in

// Call completion handler.
completion(phAsset: phAsset, image: resultImage)
})

如果问题出在上述方法中,有人知道如何提高滚动性能吗?

任何指针将不胜感激。

最佳答案

根据 Apple 文档,

If you need to load image data for many assets together, use the PHCachingImageManager class to “preheat” the cache by loading images you expect to need soon. For example, when populating a collection view with photo asset thumbnails, you can cache images ahead of the current scroll position

// Update the assets the PHCachingImageManager is caching.
[self.imageManager startCachingImagesForAssets:assetsToStartCaching
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil];
[self.imageManager stopCachingImagesForAssets:assetsToStopCaching
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil];

可以很方便的引用苹果提供的缓存帮助@Sample app https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html

关于ios - 照片框架 : UICollectionView scrolling jitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33554727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com