Swift 上载图像的预览页面

Swift 上载图像的预览页面,swift,image,uitableview,uicollectionview,Swift,Image,Uitableview,Uicollectionview,我正在做一个多图像上传过程;我希望用户预览他们选择的图像,并为图像添加一些描述。在这里,我在表视图中创建了一个集合视图,我希望图像显示在集合视图单元格中,但我不知道应该编写什么代码来调用用户拾取的图像 这是图像选择器控制器 @objc func btnClick() { let picker = YPImagePicker(configuration: config) picker.didFinishPicking { [unowned picke

我正在做一个多图像上传过程;我希望用户预览他们选择的图像,并为图像添加一些描述。在这里,我在表视图中创建了一个集合视图,我希望图像显示在集合视图单元格中,但我不知道应该编写什么代码来调用用户拾取的图像

这是图像选择器控制器

    @objc func btnClick() {
    let picker = YPImagePicker(configuration: config)
       
        picker.didFinishPicking { [unowned picker] items, _ in
            if let photo = items.singlePhoto {
                print(photo.fromCamera) // Image source (camera or library)
                print(photo.image) // Final image selected by the user
                print(photo.originalImage) // original image selected by the user, unfiltered
                print(photo.modifiedImage) // Transformed image, can be nil
                print(photo.exifMeta) // Print exif meta data of original image.
            }
            picker.dismiss(animated: true, completion: nil)
        }
        present(picker, animated: true, completion: nil)
        
        picker.didFinishPicking { [unowned picker] items, cancelled in
            for item in items {
                switch item {
                case .photo(let photo):
                    print(photo)
                case .video(let video):
                    print(video)
                }
            }
            picker.dismiss(animated: true, completion: nil)
        }

    }

performSegue(withIdentifier: "UploadTableViewController", sender: nil)
    func collectionView(collectionView: UICollectionView,
    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("UploadCollectionViewCell",
        forIndexPath: indexPath)
    cell.image?.UIImageView = 
    return cell
}
这是在tableView控制器中

    @objc func btnClick() {
    let picker = YPImagePicker(configuration: config)
       
        picker.didFinishPicking { [unowned picker] items, _ in
            if let photo = items.singlePhoto {
                print(photo.fromCamera) // Image source (camera or library)
                print(photo.image) // Final image selected by the user
                print(photo.originalImage) // original image selected by the user, unfiltered
                print(photo.modifiedImage) // Transformed image, can be nil
                print(photo.exifMeta) // Print exif meta data of original image.
            }
            picker.dismiss(animated: true, completion: nil)
        }
        present(picker, animated: true, completion: nil)
        
        picker.didFinishPicking { [unowned picker] items, cancelled in
            for item in items {
                switch item {
                case .photo(let photo):
                    print(photo)
                case .video(let video):
                    print(video)
                }
            }
            picker.dismiss(animated: true, completion: nil)
        }

    }

performSegue(withIdentifier: "UploadTableViewController", sender: nil)
    func collectionView(collectionView: UICollectionView,
    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("UploadCollectionViewCell",
        forIndexPath: indexPath)
    cell.image?.UIImageView = 
    return cell
}

我认为您必须将图像分配给cellForItemAt:indexPath中的集合视图单元格。所以你可以这样做:

cell.imageView.image =  items[indexPath.row]
还缺少的是,一旦选择了图像,就必须更新collectionView。因此,只需调用以下命令即可重新加载:

collectionView.reloadData()

希望有帮助。

在CellForRowAt中,需要在单元格的UIImageView中设置相应的图像

cell.image = imageData[indexPath.item]
imageData
是一组用户可以选择的图像数据

然后随时重新加载collectionView

collectionView.reloadData()
示例代码

func collectionView(collectionView: UICollectionView,
            cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
  let cell = collectionView.dequeueReusableCellWithReuseIdentifier("UploadCollectionViewCell",
    forIndexPath: indexPath)
  cell.image = imageData[indexPath.item]
  // It works with either item or row. But for CollectionView, .item is preferable.
  collectionView.reloadData()
  return cell
}

实际上,我的图像数据不是来自我的资产,它应该来自个人上传的图像,你可以认为它像一个相机或照片库,那么我如何将图像数据定义为个人选择的图像。或者说得更清楚一点,我希望它在上传到Firebase之前是一个预览。您有一个示例UI吗?我真的无法想象如何实现它。就像instagram上传图像功能一样,我已经开发了图像选择器会话,现在我希望在上传到firebase之前有一个预览页面。