【发布时间】:2017-12-07 18:22:00
【问题描述】:
我正在尝试使用Photos Framework。在我的collectionView 中,我想展示Camera Roll 和Personal albums 的海报图片。
我正在尝试以这种方式实现代码,但我仍然看到每张专辑的图像都相同......我哪里做错了?
我把代码放在这里...希望有人能帮助我
//USER ALBUM
@property (nonatomic, strong) PHFetchResult *userAlbum;
@property (nonatomic, strong) PHAssetCollection *assetCollection;
@property (nonatomic, strong) PHAsset *asset;
-(void)viewDidLoad {
[super viewDidLoad];
PHFetchOptions *userAlbumsOptions = [[PHFetchOptions alloc] init];
userAlbumsOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
self.userAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum | PHAssetCollectionTypeMoment subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
for (NSInteger i =0; i < self.userAlbum.count; i++) {
self.assetCollection = [self.userAlbum objectAtIndex:i];
NSLog(@"%@",[self.assetCollection.localizedTitle uppercaseString]);
PHFetchResult *fetchResult = [PHAsset fetchKeyAssetsInAssetCollection:self.assetCollection options:nil];
self.asset = [fetchResult firstObject];
}
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.userAlbum.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
KCCategoryCell *catCell = [collectionView dequeueReusableCellWithReuseIdentifier:categoryCellID forIndexPath:indexPath];
CGFloat retina = [UIScreen mainScreen].scale;
CGSize square = CGSizeMake(catCell.albumImage.bounds.size.width * retina, catCell.bounds.size.height * retina);
[[PHImageManager defaultManager] requestImageForAsset:self.asset targetSize:square contentMode:PHImageContentModeAspectFill options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
catCell.albumImage.image = result;
}];
return catCell;
}
【问题讨论】:
标签: ios objective-c uicollectionview photosframework