如何从CollectionView中删除选定的图像以及如何在Swift中从设备中将其删除

时间:2019-07-03 02:52:19

标签: ios swift uicollectionview

我在如何从collectionView删除所选图像并将其从设备中删除方面遇到问题。

将数据设置到集合视图的功能

func getPhotosUIImage(width: CGFloat) -> [UIImage] {
    var photos = [UIImage]()

    let sortingFilter = "creationDate"
    let imgManager = PHImageManager.default()
    let requestOptions = PHImageRequestOptions()
    requestOptions.isSynchronous = true
    requestOptions.deliveryMode = .highQualityFormat

    let fetchOption = PHFetchOptions()
    fetchOption.sortDescriptors = [NSSortDescriptor(key: sortingFilter, ascending: false)]

    let fetchResult : PHFetchResult = PHAsset.fetchAssets(with:.image, options: fetchOption)

    let imageSize = CGSize(width: width - (width * 0.24), height: width - (width * 0.18))
    if fetchResult.count > 0 {
        for i in 0..<fetchResult.count{
            imgManager.requestImage(for: fetchResult.object(at: i), targetSize: imageSize, contentMode: .aspectFill, options: requestOptions, resultHandler: {
                image, error in
                photos.append(image!)
            })
        }
    }
    return photos
}

该函数从设备返回所有图像,然后问题是如何基于UIImage的数组从设备删除一个图像。

0 个答案:

没有答案