iOS 相册多选图片上传

来源:互联网 发布:淘宝网店策划书ppt 编辑:程序博客网 时间:2024/05/18 03:22

原理:获取手机里的全部照片,显示在自定义的视图里


//获取到相册的所有图片

- (void)addAllPhotos{

    @WeakObj(self);

    _assetsLibrary=[[ALAssetsLibraryalloc]init];

    [_assetsLibraryenumerateGroupsWithTypes:ALAssetsGroupSavedPhotosusingBlock:^(ALAssetsGroup *group,BOOL *stop) {

        @StrongObj(self);

        if (group) {

            [group enumerateAssetsUsingBlock:^(ALAsset *result,NSUInteger index, BOOL *stop) {

                if (result) {

                    // 把相册储存到数组中,方便后面展示相册时使用

                    CGImageRef cgImage = [resultthumbnail];

                    UIImage *image = [UIImageimageWithCGImage:cgImage];

                    NSData  *imageData =UIImageJPEGRepresentation(image,0.5);

                    UIImage *newImage = [UIImageimageWithData:imageData];

                    UZGPhotoChooseModel *model=[[UZGPhotoChooseModelalloc]init];

                    model.image=newImage;

                    model.currentImageIsSelect=NO;//初始化默认未选中

                    model.showBackView=NO;//是否显示背景遮罩

                    model.row=index;

                    [self.cellInfoArrayaddObject:model];

                    [self.myCollectionViewreloadData];

                }

            }];

        }

    } failureBlock:^(NSError *error) {

        

    }];

}

//选中图片后刷新图片上面的选中数字

- (selectCellBolck)reloadCellSelectBlock:(NSIndexPath *)indexPath{

    @WeakObj(self);

    __blockUZGPhotoChooseModel *model=self.cellInfoArray[indexPath.row];

    selectCellBolck block=^(BOOL current_isSelect){

        if (selfWeak.selectNum>self.max_selectNum) {

            return;

        }

        if (current_isSelect) {

            selfWeak.selectNum++;

        }else{

            selfWeak.selectNum--;

        }

        model.currentImageIsSelect=current_isSelect;

        model.totalNum=selfWeak.selectNum;

        [selfWeak.cellInfoArrayreplaceObjectAtIndex:indexPath.rowwithObject:model];

        [selfWeak reloadCurrentNum];

        [selfWeak.myCollectionViewreloadData];

    };

    return block;

}



原创粉丝点击