iOS PhotoBrowser-ZLThumbnailViewController gets more than 900 pictures and the memory warning crashes



Optimize the memory to reduce the size of the image displayed by the cell, and then select the original image instead of getting the image from the imageview;




- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

    ZLCollectionCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:@"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;

    

    

    [[ZLPhotoToolsharePhotoTool] requestImageForAsset:assetsize:size resizeMode:PHImageRequestOptionsResizeModeExactcompletion:^(UIImage *image) {

        

//        DSLog(@"  每个cell上面的小图   image.size.width   %f    image.size.height    %f",image.size.width,image.size.height);


        

        cell.imageView.image = image;

        

        

        

        for (ZLSelectPhotoModel *modelin _arraySelectPhotos) {

            if ([model.imageNameisEqualToString:[asset valueForKey:@"filename"]]) {

                cell.btnSelect.selected =YES;

                break;

            }

        }

    }];

    

    cell.btnSelect.tag = indexPath.row;

    [cell.btnSelectaddTarget:selfaction:@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.collectionViewcellForItemAtIndexPath:[NSIndexPathindexPathForRow:btn.taginSection:0]];

    if (!btn.selected) {

        //添加图片到选中数组

        [btn.layeraddAnimation:[ZLAnimationToolanimateWithBtnStatusChanged]forKey:nil];

        if (cell.imageView.image ==nil) {

           ShowToastLong(@"该图片尚未从iCloud下载,请在系统相册中下载到本地后重新尝试,或在预览大图中加载完毕后选择");

            return;

        }

        ZLSelectPhotoModel *model = [[ZLSelectPhotoModelalloc] init];

        model.asset = asset;

        

        [[ZLPhotoToolsharePhotoTool] requestImageForAsset:assetsize:PHImageManagerMaximumSizeresizeMode:PHImageRequestOptionsResizeModeNonecompletion:^(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 = [assetvalueForKey:@"filename"];

        [_arraySelectPhotosaddObject:model];

    } else {

        for (ZLSelectPhotoModel *modelin _arraySelectPhotos) {

            if ([model.imageNameisEqualToString:[asset valueForKey:@"filename"]]) {

                [_arraySelectPhotosremoveObject:model];

                break;

            }

        }

    }

    

    btn.selected = !btn.selected;

    [selfchangePreViewStatus];

}







Guess you like

Origin blog.csdn.net/qq_27247497/article/details/51144375