如何使用 PHCachingImageManager().stopCachingImages

how to use PHCachingImageManager().stopCachingImages

我希望在 collection 视图中从相机胶卷中获取图像,并且在选择时我必须全屏显示所选图像。所以为了实现这一点,我使用了以下代码:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
    let cell : ImagesCell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImagesCell", for: indexPath) as! ImagesCell
    let asset = assets!.object(at: indexPath.row)
    PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFill, options: nil)
    {
        (image, info) -> Void in
        cell.imageThumb.image = image
    }
    return cell
}

我的屏幕如下所示:

现在点击 didSelectRow 委托中的一个单元格,我必须全屏显示图像

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
    let asset = assets!.object(at: indexPath.row)
    guard (asset.mediaType == PHAssetMediaType.image) else {
        print("Not a valid image media type")
        return
    }

    //PHCachingImageManager().stopCachingImages(for: [asset], targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFill, options: nil)

    PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width:SCREENWIDTH(),height:SCREENHEIGHT()), contentMode: .aspectFit, options: nil)
    {
        (image, info) -> Void in
        runOnMainThreadWithoutDeadlock
        {
            let storybd = UIStoryboard(name: "MediaPicker", bundle: nil)
            let previewVC = storybd.instantiateViewController(withIdentifier: "PreviewViewController") as! PreviewViewController
            previewVC.selectedImage = image
            self.present(previewVC, animated: true, completion: nil)
        }
    }
}

屏幕如下所示:

如您所见,图像看起来很模糊,即它采用了缓存图像,我想显示全尺寸图像,但我找不到实现相同尺寸的方法。

如果有人有想法,请分享,长期以来一直在寻找方法。

谢谢。

经过大量的反复试验:

PHImageManager.default().requestImageData(for: asset, options: nil) { (data, str, orientation, info) in
        let formAnImage = UIImage(data: data!)
        //you will get an original image
    }

上述选项并非对所有情况都适用,如果用户选择较旧的图像,则数据为零,因此我使用了以下解决方案:

            let options = PHImageRequestOptions()
            options.isNetworkAccessAllowed = true
            options.isSynchronous = true
            options.resizeMode = PHImageRequestOptionsResizeMode.exact
            let targetSize = CGSize(width:SCREENWIDTH(), height:SCREENHEIGHT())

            PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: PHImageContentMode.aspectFit, options: options) { (receivedImage, info) in

                if let formAnImage = receivedImage
                {
                    //You will get image here..
                }
            }