iOS PhotoBrowser - ZLThumbnailViewController 获取图片列表超过900张内存警告闪退问题



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];

}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值