我正在构建一个应用程序,可以让用户从图库中选择一个视频并将其上传到数据库。
但是,我无法选择用户将所选视频传递给UIView / UIImageView。
例如,用户选择视频但是当按下“选择”按钮时,它无法压缩并将其传递到图库中的UIView。压缩后,它将显示此输出View Image
以下代码是我的按钮,允许用户“拍摄视频”或“从图库中选择”
@IBAction func videoBtn(_ sender: Any)
{
let alert = UIAlertController(title: "Pick Image Source", message: "", preferredStyle: .alert)
let takePhotoBtn = UIAlertAction(title: "Take Video", style: .default, handler: {(_ action: UIAlertAction) -> Void in
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let VideoViewController = storyBoard.instantiateViewController(withIdentifier: "VideoViewController") as! VideoViewController
self.present(VideoViewController, animated:true, completion:nil)
})
let galleryBtn = UIAlertAction(title: "Select from Gallery", style: .default, handler: {(_ action: UIAlertAction) -> Void in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
imagePicker.mediaTypes = ["public.movie"]
}
})
let cancelBtn = UIAlertAction(title: "Cancel", style: .default, handler: {(_ action: UIAlertAction) -> Void in
// print("Cancel")
})
alert.addAction(takePhotoBtn)
alert.addAction(galleryBtn)
alert.addAction(cancelBtn)
present(alert, animated: true, completion: { _ in })
}