欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS实现相册多选图片上传功能

程序员文章站 2023-12-21 08:01:51
本文实例为大家分享了ios实现相册多选图片上传的具体代码,供大家参考,具体内容如下 原理:获取手机里的全部照片,显示在自定义的视图里 //获取到相册的所有图片...

本文实例为大家分享了ios实现相册多选图片上传的具体代码,供大家参考,具体内容如下

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

//获取到相册的所有图片
- (void)addallphotos{
  @weakobj(self);
  _assetslibrary=[[alassetslibrary alloc]init];
  [_assetslibrary enumerategroupswithtypes:alassetsgroupsavedphotos usingblock:^(alassetsgroup *group, bool *stop) {
    @strongobj(self);
    if (group) {
      [group enumerateassetsusingblock:^(alasset *result, nsuinteger index, bool *stop) {
        if (result) {
          // 把相册储存到数组中,方便后面展示相册时使用
          cgimageref cgimage = [result thumbnail];
          uiimage *image = [uiimage imagewithcgimage:cgimage];
          nsdata *imagedata = uiimagejpegrepresentation(image,0.5);
          uiimage *newimage = [uiimage imagewithdata:imagedata];
          uzgphotochoosemodel *model=[[uzgphotochoosemodel alloc]init];
          model.image=newimage;
          model.currentimageisselect=no;//初始化默认未选中
          model.showbackview=no;//是否显示背景遮罩
          model.row=index;
          [self.cellinfoarray addobject:model];
          [self.mycollectionview reloaddata];
        }
      }];
    }
  } failureblock:^(nserror *error) {
    
  }];
}
//选中图片后刷新图片上面的选中数字
- (selectcellbolck)reloadcellselectblock:(nsindexpath *)indexpath{
  @weakobj(self);
  __block uzgphotochoosemodel *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.cellinfoarray replaceobjectatindex:indexpath.row withobject:model];
    [selfweak reloadcurrentnum];
    [selfweak.mycollectionview reloaddata];
  };
  return block;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: