gpt4 book ai didi

iOS PHImageManager.default().requestImage 回调被同一张图片调用两次

转载 作者:搜寻专家 更新时间:2023-11-01 06:49:57 30 4
gpt4 key购买 nike

当我尝试获取具有特定尺寸的图像时,PHImageManager.default().requestImage 被调用两次,并使用不同尺寸的图像。

代码如下:

static func load(from asset: PHAsset, targetSize: CGSize? = nil, completion: @escaping (UIImage?)->()) {
let options = PHImageRequestOptions()
options.isSynchronous = false
let id = UUID()
PHImageManager.default().requestImage(for: asset, targetSize: targetSize ?? PHImageManagerMaximumSize, contentMode: .aspectFill,
options: options, resultHandler: { image, _ in
print(id)
runInMain {
completion(image)
}
})
}

我添加了 UUID 以检查相同的 UUID 是否被打印了两次。

最佳答案

这是因为第一个回调在加载全尺寸图像时返回缩略图。

来自official Apple documentation:

For an asynchronous request, Photos may call your result handler block more than once. Photos first calls the block to provide a low-quality image suitable for displaying temporarily while it prepares a high-quality image. (If low-quality image data is immediately available, the first call may occur before the method returns.) When the high-quality image is ready, Photos calls your result handler again to provide it. If the image manager has already cached the requested image at full quality, Photos calls your result handler only once. The PHImageResultIsDegradedKey key in the result handler’s info parameter indicates when Photos is providing a temporary low-quality image.

关于iOS PHImageManager.default().requestImage 回调被同一张图片调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58198525/

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