cell里面显示缩略图尺寸变小一点,获取是获取原图;
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ZLCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZLCollectionCell" forIndexPath:indexPath];
cell.btnSelect.selected = NO;
PHAsset *asset = _arrayDataSources[indexPath.row];
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.clipsToBounds = YES;
CGSize size = cell.frame.size;
// size.width *= 10;
// size.height *= 10;
size.width *= 2;
size.height *= 2;
[[ZLPhotoTool sharePhotoTool] requestImageForAsset:asset size:size resizeMode:PHImageRequestOptionsResizeModeExact completion:^(UIImage *image) {
// DSLog(@" 每个cell上面的小图 image.size.width %f image.size.height %f",image.size.width,image.size.height);
cell.imageView.image = image;
for (ZLSelectPhotoModel *model in _arraySelectPhotos) {
if ([model.imageName isEqualToString:[asset valueForKey:@"filename"]]) {
cell.btnSelect.selected = YES;
break;
}
}
}];
cell.btnSelect.tag = indexPath.row;
[cell.btnSelect addTarget:self action:@selector(cell_btn_Click:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
#pragma mark - UIButton Action
- (void)cell_btn_Click:(UIButton *)btn
{
DSLog(@"点击选择照片按钮");
if (_arraySelectPhotos.count >= self.maxSelectCount
&& btn.selected == NO) {
ShowToastLong(@"最多只能选择%ld张图片", (long)self.maxSelectCount);
return;
}
PHAsset *asset = _arrayDataSources[btn.tag];
ZLCollectionCell *cell = (ZLCollectionCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:btn.tag inSection:0]];
if (!btn.selected) {
//添加图片到选中数组
[btn.layer addAnimation:[ZLAnimationTool animateWithBtnStatusChanged] forKey:nil];
if (cell.imageView.image == nil) {
ShowToastLong(@"该图片尚未从iCloud下载,请在系统相册中下载到本地后重新尝试,或在预览大图中加载完毕后选择");
return;
}
ZLSelectPhotoModel *model = [[ZLSelectPhotoModel alloc] init];
model.asset = asset;
[[ZLPhotoTool sharePhotoTool] requestImageForAsset:asset size:PHImageManagerMaximumSize resizeMode:PHImageRequestOptionsResizeModeNone completion:^(UIImage *image) {
// DSLog(@" 选中后 每个cell上面的原图 image.size.width %f image.size.height %f",image.size.width,image.size.height);
model.image = image;
}];
// model.image = cell.imageView.image;
model.imageName = [asset valueForKey:@"filename"];
[_arraySelectPhotos addObject:model];
} else {
for (ZLSelectPhotoModel *model in _arraySelectPhotos) {
if ([model.imageName isEqualToString:[asset valueForKey:@"filename"]]) {
[_arraySelectPhotos removeObject:model];
break;
}
}
}
btn.selected = !btn.selected;
[self changePreViewStatus];
}