我正在为我的项目使用Fusuma pod,但是在上一个iOS 13中,有一个与图像相关的错误是从Gallery中选择的。
确切地说,如果选择的图像来自Gallery(在装有iOS 13的iPhone设备上,而不是模拟器上),则图像的尺寸为width:39和height:39,以下功能为 Fusuma ,位于 FusumaViewController
private func requestImage(with asset: PHAsset, cropRect: CGRect, completion: @escaping (PHAsset, UIImage) -> Void) {
DispatchQueue.global(qos: .default).async(execute: {
let options = PHImageRequestOptions()
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
options.normalizedCropRect = cropRect
options.resizeMode = .exact
let targetWidth = floor(CGFloat(asset.pixelWidth) * cropRect.width)
let targetHeight = floor(CGFloat(asset.pixelHeight) * cropRect.height)
let dimensionW = max(min(targetHeight, targetWidth), 1024 * UIScreen.main.scale)
let dimensionH = dimensionW * self.getCropHeightRatio()
let targetSize = CGSize(width: dimensionW, height: dimensionH)
PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFill, options: options) { result, info in
guard let result = result else { return }
DispatchQueue.main.async(execute: {
completion(asset, result)
})
}
})
}
private func fusumaDidFinishInMultipleMode() {
guard let view = albumView.imageCropView else { return }
let normalizedX = view.contentOffset.x / view.contentSize.width
let normalizedY = view.contentOffset.y / view.contentSize.height
let normalizedWidth = view.frame.width / view.contentSize.width
let normalizedHeight = view.frame.height / view.contentSize.height
let cropRect = CGRect(x: normalizedX,
y: normalizedY,
width: normalizedWidth,
height: normalizedHeight)
var images = [UIImage]()
var metaData = [ImageMetadata]()
for asset in albumView.selectedAssets {
requestImage(with: asset, cropRect: cropRect) { asset, result in
images.append(result)
metaData.append(self.getMetaData(asset: asset))
if asset == self.albumView.selectedAssets.last {
self.doDismiss {
self.delegate?.fusumaMultipleImageSelected(images, source: self.mode, metaData: metaData)
}
}
}
}
}
requestImage(...)函数返回的图像尺寸不正确
答案 0 :(得分:0)
文档说PHImageManager
可能多次调用requestImage
完成,而最后一次调用应具有请求的targetSize
的图像。