问题描述
我想在选择后编辑/压缩视频,就像在 UIImagePickerController
中使用 allowsEditing = true
一样。
新的 PHPickerViewController
仍然没有这个属性,Apple
说没有这个属性了 here。但是 App Store 中有应用在从 PHPickerViewController
这是我的 PHPickerViewController 实现:
func openImagePicker() {
if #available(iOS 14,*) {
var configuration = PHPickerConfiguration()
configuration.preferredAssetRepresentationMode = .automatic
let picker = PHPickerViewController(configuration: configuration)
// Set the delegate
picker.delegate = self
// Present the picker
present(picker,animated: true)
} else {
// Fallback on earlier versions
imagePicker?.photogalleryAsscessRequest()
}
}
extension EditController: PHPickerViewControllerDelegate {
@available(iOS 14,*)
func picker(_ picker: PHPickerViewController,didFinishPicking results: [PHPickerResult]) {
self.dismiss(animated: true)
}
}
解决方法
我调查了这个问题,但确实没有像你提到的那样支持 allowsediting
。
例如,与您的问题相关的视频编辑预设值已折旧为 UIImagePickerController.ImageURLExportPreset.compatible
,但不支持自动压缩。选择器将始终传递原始视频/图像,由应用程序进行必要的压缩或编辑。
您可以查看此 Apple 文档:imageExportPreset。
Apple 特别提到我们应该使用这个新的而不是旧的 UIImagePickerViewController。如果有人想知道更多:Meet the new Photos picker