我在如何从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
的数组从设备删除一个图像。