-1

我是 IOS 新手,我正在使用第三方库来集成我的多个图像/视频选择器。图书馆链接https://github.com/hyperoslo/Gallery

本地图像/视频显示速度足够快,但问题是一旦我使用 iCloud 包含超过 500 多张图像,它需要将近 1 分钟。第一次加载,是他们的任何解决方案减少或几乎消除加载时间。

这是我的代码快照,可能会有所帮助

class MyGalleryViewController: UIViewController,     GalleryControllerDelegate,UITabBarControllerDelegate{
let gallery = GalleryController()
override func viewDidLoad() {
super.viewDidLoad()

    openGallery()     
}
private func openGallery(){
    gallery.delegate = self
    gallery.modalPresentationStyle = .fullScreen
    present(gallery, animated: true, completion: nil)
}
//Rest of galleryController function
}

非常感谢提前。

4

1 回答 1

1

您需要遵循以下步骤:

  • 为 iCloud 上的图像获取 PHAsset
 PHAsset.fetchAssets(with: .image, options: PHFetchOptions())
    // Images on iCloud will be included
  • 请求资产图片
let imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.deliveryMode = .opportunistic
imageRequestOptions.isNetworkAccessAllowed = true // allowing iCloud image downloaded from network
imageRequestOptions.progressHandler = progressHandler // progressHandler is outer callback, may be called multiple times

PHCachingImageManager.default().requestImage(for: asset)
  • 在 PHAssetImageProgressHandler 处理图片下载进度
let progressHandler: PHAssetImageProgressHandler = { (progress, _, stop, _) in
    cell.updateProgress(CGFloat(progress))
}

iCloud镜像的关键:

  1. PHImageRequestOptions.isNetworkAccessAllowed
  2. PHImageRequestOptions.progressHandler
于 2020-04-17T09:55:13.550 回答