0
私は、コレクションビューでカメラロールから画像をフェッチしたいのですが、選択した画像をフルスクリーンで表示する必要があります。PHCachingImageManager()の使い方stopCachingImages
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)
}
}
}
画面は以下のようになります。
ご覧のとおり、画像がぼやけて見えます。つまり、キャッシュされた画像が表示されます。フルサイズの画像を表示したいのですが、同じ方法を見つけることができません。
誰かがアイデアを持っていれば分かち合い、長い間道を探してください。
ありがとうございました。試行錯誤の多くの後