如何在Swift中的didFinishPickingMediaWithInfo之前知道在photoLibrary中选择的mediatype?

时间:2018-05-08 08:32:41

标签: swift uiimagepickercontroller gallery

我需要知道在didFinishPickingMediaWithInfo之前选择的mediaType才能允许根据类型进行编辑。

如果您选择视频,那么它将是真的,如果您选择图像,它将是假的。

在sourceType = .camera的情况下,我这样做了:

cameraController.allowsEditing = cameraController.cameraCaptureMode == .video

1 个答案:

答案 0 :(得分:0)

您可以选择mediaTypes

来执行此操作
 var imagePicker = UIImagePickerController()  

适用于相机:

if UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
   cameraController.sourceType = UIImagePickerControllerSourceType.camera
   cameraController.allowsEditing = cameraController.cameraCaptureMode == .video

   self.present(imagePicker, animated: true, completion: nil
 } 

对于来自图库的视频:您可以选择媒体类型:

cameraController.sourceType = UIImagePickerControllerSourceType.photoLibrary
cameraController.mediaTypes = [kUTTypeMovie as String]
cameraController.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)

仅适用于图片:

cameraController.sourceType = UIImagePickerControllerSourceType.photoLibrary
cameraController.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)

如需了解详情,请点击链接:https://medium.com/@deepakrajmurugesan/swift-access-ios-camera-photo-library-video-and-file-from-user-device-6a7fd66beca2