gpt4 book ai didi

ios 13 PHImageManager.default().requestImage 和 Fusuma

转载 作者:行者123 更新时间:2023-11-29 05:25:35 24 4
gpt4 key购买 nike

我在我的项目中使用 Fusuma pod,但在最新的 iOS 13 中,存在一个与从图库中选择的图像相关的错误。

确切地说,如果选择的图像来自图库(在带有 ios 13 的 iPhone 设备上,而不是模拟器),则图像的尺寸为宽度:39 和高度: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(...) 函数返回不正确的图像大小

最佳答案

文档说 PHImageManager 可能会多次调用 requestImage 完成,最终调用应该有一个具有请求的 targetSize 的图像。

关于ios 13 PHImageManager.default().requestImage 和 Fusuma,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58213670/

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