Sem*_*nko 4 ios swift photokit
当我尝试获取特定大小的图像时,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)
}
})
}
Run Code Online (Sandbox Code Playgroud)
我添加了 UUID 来检查相同的 UUID 是否打印了两次。
Gur*_*ngh 10
Swift 5它仅使用.deliveryMode = .highQualityFormat调用一次
let manager = PHImageManager.default()
var imageRequestOptions: PHImageRequestOptions {
let options = PHImageRequestOptions()
options.version = .current
options.resizeMode = .exact
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
options.isSynchronous = true
return options
}
self.manager.requestImage(for: asset,targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: self.imageRequestOptions) { (thumbnail, info) in
if let img = thumbnail {
print(img)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1719 次 |
| 最近记录: |