如何从相机胶卷中选择多个图像和视频并将其显示在collectionView中?

时间:2018-10-07 14:13:42

标签: ios swift uicollectionview uiimagepickercontroller

我一直在使用以下代码来选择图像并通过UIImageView显示它:

class ViewController UIViewContoller, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    @IBOutlet weak var imageView: UIImageView!
    let imagePicker = UIImagePickerController()

    override func viewDidLoad(){
        super.viewDidLoad()
        imagePicker.delegate = self
    }

    @IBAction func loadImage(_ sender: Any){
        imagePicker.allowsEditing = false
        imagePicker.sourceType = .photoLibrary
        present(imagePicker, animated: true, completion: nil)
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]){
        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
            imageView.contentMode = .scaleAspectFit
            imageView.image = pickedImage
        }
        dismiss(animated: true completion: nil)
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
        dismiss(animated: true, completion: nil)
    }
}

如何使用UIImagePickerController类选择多个图像和视频并将其显示在集合视图中?

1 个答案:

答案 0 :(得分:0)

  

如何使用UIImagePickerController类选择多个图像和视频

不能。 UIImagePickerController允许用户选择一个图片/视频。