RITLPhotosBrowseAllDataSource.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // RITLPhotosBrowseAllDataSource.m
  3. // RITLPhotoDemo
  4. //
  5. // Created by YueWen on 2018/5/10.
  6. // Copyright © 2018年 YueWen. All rights reserved.
  7. //
  8. #import "RITLPhotosBrowseAllDataSource.h"
  9. #import "PHAsset+RITLPhotos.h"
  10. #import "UICollectionViewCell+RITLPhotosAsset.h"
  11. @interface RITLPhotosBrowseAllDataSource ()
  12. ///存储资源的对象
  13. @property (nonatomic, strong, readwrite) PHFetchResult<PHAsset *> *assetResult;
  14. ///进行资源化的Manager
  15. @property (nonatomic, strong, readwrite) PHCachingImageManager* imageManager;
  16. @end
  17. @implementation RITLPhotosBrowseAllDataSource
  18. - (instancetype)init
  19. {
  20. if (self = [super init]) {
  21. self.imageManager = PHCachingImageManager.new;
  22. }
  23. return self;
  24. }
  25. - (void)setCollection:(PHAssetCollection *)collection
  26. {
  27. _collection = collection;
  28. self.assetResult = [PHAsset fetchAssetsInAssetCollection:self.collection options:nil];
  29. }
  30. #pragma mark - <UICollectionViewDataSource>
  31. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  32. {
  33. return self.assetResult.count;
  34. }
  35. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  36. {
  37. //获得当前的对象
  38. PHAsset *asset = [self.assetResult objectAtIndex:indexPath.item];
  39. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:asset.ritl_type forIndexPath:indexPath];
  40. [cell updateAssets:asset atIndexPath:indexPath imageManager:self.imageManager];//即将显示,进行填充
  41. return cell;
  42. }
  43. #pragma mark - <RITLPhotosHorBrowseDataSource>
  44. - (PHAsset *)assetAtIndexPath:(NSIndexPath *)indexPath
  45. {
  46. return [self.assetResult objectAtIndex:indexPath.item];
  47. }
  48. - (NSIndexPath *)defaultItemIndexPath
  49. {
  50. return [NSIndexPath indexPathForItem:[self.assetResult indexOfObject:self.asset] inSection:0];
  51. }
  52. - (void)dealloc
  53. {
  54. NSLog(@"[%@] is dealloc",NSStringFromClass(self.class));
  55. }
  56. @end