当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS实现相册多选图片上传功能

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

护士打针,全频段对讲机,国家宝藏之觐天宝匣2

本文实例为大家分享了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;
}

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网