所以我使用下面的代码从运行良好的库中获取所有图像:
func grabPhotos(){
let imgManager = PHImageManager.default()
let requestOptions = PHImageRequestOptions()
requestOptions.isSynchronous = true
requestOptions.deliveryMode = .highQualityFormat
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
if let fetchResults : PHFetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions){
if fetchResults.count>0{
for i in 0..<fetchResults.count{
imgManager.requestImage(for: fetchResults.object(at: i), targetSize: CGSize(width:100, height: 100), contentMode: .aspectFill, options: requestOptions, resultHandler: {
image, error in
self.Galleryimages.append(image!)
print("array count is ",self.Galleryimages.count)
self.photoCollectionview.reloadData()
})
}
}
}
}
我在我的 UICollectionView 中显示所有图像,但是每当单击任何缩略图图像时,我都找不到任何方法来获取原始图像。当用户单击 UICollectionView 中填充的任何缩略图图像时,我想获取原始图像(全尺寸图像)。
谢谢你。