美文网首页iOS 技术分享
iOS - 相册多选图片

iOS - 相册多选图片

作者: Joh蜗牛 | 来源:发表于2019-04-19 17:09 被阅读0次

    1.在pod中导入三方工具:

    pod 'TZImagePickerController'
    

    2.调用相册:

    在页面引入:
    #import <TZImagePickerController.h>
    代理方法<TZImagePickerControllerDelegate>
    
    // 相册
    - (void)photoClick{
    
        NSInteger Count =  9 - self.dataSource.count;//剩余可选图片数量
        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:Count delegate:self];
        [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photo, NSArray * assets, BOOL isSelectOriginalPhoto) {
            NSMutableArray *imgAry = [@[] mutableCopy];
            for (NSInteger i = 0; i<photo.count; i++) {
                UIImage *img = [ImageUtil zipImgWithImage:photo[i]];//压缩图片
                [imgAry addObject:img];
            }
           
        }];
        [self presentViewController:imagePickerVc animated:YES completion:nil];
    
    }
    

    3.顺便说下调用相机:

    // 相机
    - (void)cameraClick{
    
        NSUInteger sourceType = 0;
        // 判断系统是否支持相机
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            imagePickerController.delegate = self; //设置代理
            imagePickerController.allowsEditing = NO;
            imagePickerController.sourceType = sourceType; //图片来源
            //拍照
            sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePickerController.sourceType = sourceType;
            [self presentViewController:imagePickerController animated:YES completion:nil];
        }
    
    }
    
    
    // 获取图片
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
        [picker dismissViewControllerAnimated:YES completion:^{}];
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //通过key值获取到图片
        UIImage *img = [GlobelConfig imageCompressToData:image];//压缩图片
    
    }
    

    相关文章

      网友评论

        本文标题:iOS - 相册多选图片

        本文链接:https://www.haomeiwen.com/subject/hzdcgqtx.html