PHCachingImageManager简单记录
PHCachingImageManager简单记录
杨志强 发表于2年前
PHCachingImageManager简单记录
  • 发表于 2年前
  • 阅读 170
  • 收藏 0
  • 点赞 2
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

摘要: 记录PHCachingImageManager的使用。

注意:IOS 8.0之后可以使用

简单来说,IOS获取相册现在有了官方的缓冲机制了。

1.创建出PHCachingImageManager对象,

2.使用

- (void)startCachingImagesForAssets:(NSArray<PHAsset *> *)assets
                         targetSize:(CGSize)targetSize
                        contentMode:(PHImageContentMode)contentMode
                            options:(PHImageRequestOptions *)options

 

3.使用

- (PHImageRequestID)requestImageForAsset:(PHAsset *)asset
                              targetSize:(CGSize)targetSize
                             contentMode:(PHImageContentMode)contentMode
                                 options:(PHImageRequestOptions *)options
                           resultHandler:(void (^)(UIImage *result,
                                                   NSDictionary *info))resultHandler

在resultHandler中把result赋值给对应的UIImageView就OK了。(asset必须在assets中,targetSize必须相同,contentMode必须相同,options必须相同)

 

附官方例子:

https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Listings/SamplePhotosApp_AAPLAssetGridViewController_m.html

附官方说明:

To use a caching image manager:

  1. Create a PHCachingImageManager instance. (This step replaces using the shared PHImageManagerinstance.)

  2. Use PHAsset class methods to fetch the assets you’re interested in.

  3. To prepare images for those assets, call thestartCachingImagesForAssets:targetSize:contentMode:options: method with the target size, content mode, and options you plan to use when later requesting images for each individual asset.

  4. When you need an image for an individual asset, call therequestImageForAsset:targetSize:contentMode:options:resultHandler: method, and pass the same parameters you used when preparing that asset.

    If the image you request is among those already prepared, the PHCachingImageManager object immediately returns that image. Otherwise, Photos prepares the image on demand and caches it for later use.

共有 人打赏支持
粉丝 3
博文 2
码字总数 261
×
杨志强
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: