Commit 4d6a93673b2a9312edc83974a0250fd8a8591a78
1 parent
6f2aa2be
提交0.0.14
Showing
3 changed files
with
151 additions
and
118 deletions
CNLiveImagePickerController.podspec
CNLiveImagePickerController/Classes/TZPhotoPickerController.m
| ... | ... | @@ -571,6 +571,15 @@ static CGFloat itemMargin = 5; |
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | + if (tzImagePickerVc.maxImagesCount == 1) { | |
| 575 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 576 | + [tzImagePickerVc hideProgressHUD]; | |
| 577 | + [tzImagePickerVc hideAlertView:alertView]; | |
| 578 | + }); | |
| 579 | + [weakSelf didGetAllPhotos:photos assets:assets selectedModels:selectedModels infoArr:infoArr]; | |
| 580 | + return; | |
| 581 | + } | |
| 582 | + | |
| 574 | 583 | if (havenotShowAlert) { |
| 575 | 584 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 576 | 585 | [tzImagePickerVc hideProgressHUD]; | ... | ... |
Example/CNLiveImagePickerController/CNLiveViewController.m
| ... | ... | @@ -36,126 +36,150 @@ |
| 36 | 36 | // [CNImagePickerManager ImagePickerWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES isSelectOriginalPhoto:nil selectedAssets:nil enterType:CNImagePickerEnterTypeFriendsCircle pickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { |
| 37 | 37 | // |
| 38 | 38 | // }]; |
| 39 | +// | |
| 40 | +// CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc]initWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES]; | |
| 41 | +// [imagePickerVc configTZImagePicker];//配置 | |
| 42 | +// imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; | |
| 43 | +// imagePickerVc.isSelectOriginalPhoto = NO;//是否选择原图 | |
| 44 | +// // 1.设置目前已经选中的图片数组 | |
| 45 | +// imagePickerVc.selectedAssets = nil; // 目前已经选中的图片数组 | |
| 46 | +// // 发布时长限制 | |
| 47 | +// imagePickerVc.maxEditVideoTime = kChat_limit_video_length_upload; | |
| 48 | +// imagePickerVc.maxVideoDuration = kChat_limit_video_length_upload; | |
| 49 | +// imagePickerVc.conversationId = @"defult"; | |
| 50 | +// imagePickerVc.timeout = 300; | |
| 51 | +// imagePickerVc.isExportVideo = YES;//允许导出 | |
| 52 | +// /// 5. Single selection mode, valid when maxImagesCount = 1 | |
| 53 | +// /// 5. 单选模式,maxImagesCount为1时才生效 | |
| 54 | +// // 设置竖屏下的裁剪尺寸 | |
| 55 | +// NSInteger left = 30; | |
| 56 | +// NSInteger widthHeight = self.view.width - 2 * left; | |
| 57 | +// NSInteger top = (self.view.height - widthHeight) / 2; | |
| 58 | +// imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight); | |
| 59 | +// | |
| 60 | +// // You can get the photos by block, the same as by delegate. | |
| 61 | +// // 你可以通过block或者代理,来得到用户选择的照片. | |
| 62 | +// __weak typeof(self) weakSelf = self; | |
| 63 | +// [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 64 | +// | |
| 65 | +// }]; | |
| 66 | +// [imagePickerVc setImagePickerControllerDidCancelHandle:^{ | |
| 67 | +// | |
| 68 | +// | |
| 69 | +// }]; | |
| 70 | +// [imagePickerVc setDidNewFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray<TZAssetModel *> *models, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 71 | +// NSLog(@"输出models = %@",models); | |
| 72 | +// // | |
| 73 | +// NSMutableArray *operationArray = [NSMutableArray new]; | |
| 74 | +// for (int i = 0; i < photos.count;i++ ) { | |
| 75 | +// | |
| 76 | +// NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
| 77 | +// UIImage *img = photos[i]; | |
| 78 | +// TZAssetModel *model = models[i]; | |
| 79 | +// | |
| 80 | +// //进行图片视频压缩(LXG) | |
| 81 | +// if (model.type == TZAssetModelMediaTypeVideo) | |
| 82 | +// {//视频 | |
| 83 | +// NSError *err = nil; | |
| 84 | +// if (!model.exportURL) { | |
| 85 | +// NSLog(@"///////导出失败"); | |
| 86 | +// return; | |
| 87 | +// } | |
| 88 | +// NSData* data = [NSData dataWithContentsOfURL:model.exportURL options:NSDataReadingMappedIfSafe error:&err]; | |
| 89 | +// | |
| 90 | +// NSLog(@"已经导出视频"); | |
| 91 | +// | |
| 92 | +// | |
| 93 | +// }else | |
| 94 | +// { | |
| 95 | +// | |
| 96 | +// if ([CNLiveBusinessTools isGif:assets[i]]) { | |
| 97 | +// img.isGif = @"1"; | |
| 98 | +// PHImageManager *imageManager = [PHImageManager defaultManager]; | |
| 99 | +// PHImageRequestOptions *options = [PHImageRequestOptions new]; | |
| 100 | +// options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat; | |
| 101 | +// options.resizeMode = PHImageRequestOptionsResizeModeNone; | |
| 102 | +// // options.networkAccessAllowed = YES; | |
| 103 | +// [imageManager requestImageDataForAsset:assets[i] options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { | |
| 104 | +// img.imageData = imageData; | |
| 105 | +// if (imageData.length > kChat_limit_photo_upload) { | |
| 106 | +// dispatch_async(dispatch_get_main_queue(), ^{ | |
| 107 | +// | |
| 108 | +// NSLog(@"图片过大"); | |
| 109 | +// }); | |
| 110 | +// } | |
| 111 | +// else{ | |
| 112 | +// NSLog(@"发送图片"); | |
| 113 | +// } | |
| 114 | +// | |
| 115 | +// }]; | |
| 116 | +// } | |
| 117 | +// else | |
| 118 | +// { | |
| 119 | +// | |
| 120 | +// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
| 121 | +// // 进行图片压缩(LXG) | |
| 122 | +// NSData *zipData = nil; | |
| 123 | +// if (isSelectOriginalPhoto) {//是否原图 | |
| 124 | +// zipData = [UIImage zipNSDataWithImage:img isOriginal:YES];//原图压缩 | |
| 125 | +// | |
| 126 | +// }else{ | |
| 127 | +// //zipNSDataWithImage | |
| 128 | +// zipData = [UIImage zipNSDataWithImage:img];//非原图压缩1028 | |
| 129 | +// } | |
| 130 | +// | |
| 131 | +// if (zipData.length > kChat_limit_photo_upload) {//压缩后大于20M | |
| 132 | +// dispatch_async(dispatch_get_main_queue(), ^{ | |
| 133 | +// if (isSelectOriginalPhoto) { | |
| 134 | +// NSLog(@"发送的原图过大"); | |
| 135 | +// }else{ | |
| 136 | +// NSLog(@"发送的图过大"); | |
| 137 | +// } | |
| 138 | +// }); | |
| 139 | +// } | |
| 140 | +// else{ | |
| 141 | +// NSLog(@"发送图片"); | |
| 142 | +// } | |
| 143 | +// | |
| 144 | +// }); | |
| 145 | +// | |
| 146 | +// } | |
| 147 | +// | |
| 148 | +// } | |
| 149 | +// }]; | |
| 150 | +// | |
| 151 | +// [operationArray addObject:operation]; | |
| 152 | +// | |
| 153 | +// } | |
| 154 | +// | |
| 155 | +// | |
| 156 | +// }]; | |
| 157 | +// | |
| 158 | +// [self presentViewController:imagePickerVc animated:YES completion:nil]; | |
| 39 | 159 | |
| 40 | - CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc]initWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES]; | |
| 41 | - [imagePickerVc configTZImagePicker];//配置 | |
| 42 | - imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; | |
| 43 | - imagePickerVc.isSelectOriginalPhoto = NO;//是否选择原图 | |
| 44 | - // 1.设置目前已经选中的图片数组 | |
| 45 | - imagePickerVc.selectedAssets = nil; // 目前已经选中的图片数组 | |
| 46 | - // 发布时长限制 | |
| 47 | - imagePickerVc.maxEditVideoTime = kChat_limit_video_length_upload; | |
| 48 | - imagePickerVc.maxVideoDuration = kChat_limit_video_length_upload; | |
| 49 | - imagePickerVc.conversationId = @"defult"; | |
| 50 | - imagePickerVc.timeout = 300; | |
| 51 | - imagePickerVc.isExportVideo = YES;//允许导出 | |
| 52 | - /// 5. Single selection mode, valid when maxImagesCount = 1 | |
| 53 | - /// 5. 单选模式,maxImagesCount为1时才生效 | |
| 54 | - // 设置竖屏下的裁剪尺寸 | |
| 55 | - NSInteger left = 30; | |
| 56 | - NSInteger widthHeight = self.view.width - 2 * left; | |
| 57 | - NSInteger top = (self.view.height - widthHeight) / 2; | |
| 58 | - imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight); | |
| 59 | - | |
| 60 | - // You can get the photos by block, the same as by delegate. | |
| 61 | - // 你可以通过block或者代理,来得到用户选择的照片. | |
| 62 | - __weak typeof(self) weakSelf = self; | |
| 63 | - [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 64 | - | |
| 65 | - }]; | |
| 66 | - [imagePickerVc setImagePickerControllerDidCancelHandle:^{ | |
| 67 | - | |
| 68 | - | |
| 69 | - }]; | |
| 70 | - [imagePickerVc setDidNewFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray<TZAssetModel *> *models, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 71 | - NSLog(@"输出models = %@",models); | |
| 72 | - // | |
| 73 | - NSMutableArray *operationArray = [NSMutableArray new]; | |
| 74 | - for (int i = 0; i < photos.count;i++ ) { | |
| 75 | - | |
| 76 | - NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
| 77 | - UIImage *img = photos[i]; | |
| 78 | - TZAssetModel *model = models[i]; | |
| 79 | - | |
| 80 | - //进行图片视频压缩(LXG) | |
| 81 | - if (model.type == TZAssetModelMediaTypeVideo) | |
| 82 | - {//视频 | |
| 83 | - NSError *err = nil; | |
| 84 | - if (!model.exportURL) { | |
| 85 | - NSLog(@"///////导出失败"); | |
| 86 | - return; | |
| 87 | - } | |
| 88 | - NSData* data = [NSData dataWithContentsOfURL:model.exportURL options:NSDataReadingMappedIfSafe error:&err]; | |
| 89 | - | |
| 90 | - NSLog(@"已经导出视频"); | |
| 91 | - | |
| 92 | - | |
| 93 | - }else | |
| 94 | - { | |
| 95 | - | |
| 96 | - if ([CNLiveBusinessTools isGif:assets[i]]) { | |
| 97 | - img.isGif = @"1"; | |
| 98 | - PHImageManager *imageManager = [PHImageManager defaultManager]; | |
| 99 | - PHImageRequestOptions *options = [PHImageRequestOptions new]; | |
| 100 | - options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat; | |
| 101 | - options.resizeMode = PHImageRequestOptionsResizeModeNone; | |
| 102 | - // options.networkAccessAllowed = YES; | |
| 103 | - [imageManager requestImageDataForAsset:assets[i] options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { | |
| 104 | - img.imageData = imageData; | |
| 105 | - if (imageData.length > kChat_limit_photo_upload) { | |
| 106 | - dispatch_async(dispatch_get_main_queue(), ^{ | |
| 107 | - | |
| 108 | - NSLog(@"图片过大"); | |
| 109 | - }); | |
| 110 | - } | |
| 111 | - else{ | |
| 112 | - NSLog(@"发送图片"); | |
| 113 | - } | |
| 114 | - | |
| 115 | - }]; | |
| 116 | - } | |
| 117 | - else | |
| 118 | - { | |
| 119 | - | |
| 120 | - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
| 121 | - // 进行图片压缩(LXG) | |
| 122 | - NSData *zipData = nil; | |
| 123 | - if (isSelectOriginalPhoto) {//是否原图 | |
| 124 | - zipData = [UIImage zipNSDataWithImage:img isOriginal:YES];//原图压缩 | |
| 125 | - | |
| 126 | - }else{ | |
| 127 | - //zipNSDataWithImage | |
| 128 | - zipData = [UIImage zipNSDataWithImage:img];//非原图压缩1028 | |
| 129 | - } | |
| 130 | - | |
| 131 | - if (zipData.length > kChat_limit_photo_upload) {//压缩后大于20M | |
| 132 | - dispatch_async(dispatch_get_main_queue(), ^{ | |
| 133 | - if (isSelectOriginalPhoto) { | |
| 134 | - NSLog(@"发送的原图过大"); | |
| 135 | - }else{ | |
| 136 | - NSLog(@"发送的图过大"); | |
| 137 | - } | |
| 138 | - }); | |
| 139 | - } | |
| 140 | - else{ | |
| 141 | - NSLog(@"发送图片"); | |
| 142 | - } | |
| 143 | - | |
| 144 | - }); | |
| 145 | - | |
| 146 | - } | |
| 147 | - | |
| 148 | - } | |
| 149 | - }]; | |
| 150 | - | |
| 151 | - [operationArray addObject:operation]; | |
| 152 | - | |
| 153 | - } | |
| 160 | + | |
| 161 | + | |
| 162 | + TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:2 delegate:self]; | |
| 163 | + imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; | |
| 164 | + imagePickerVc.allowTakePicture = NO; // 在内部显示拍照按钮 | |
| 165 | + imagePickerVc.allowPreview = NO; | |
| 166 | + imagePickerVc.allowPickingOriginalPhoto = NO; | |
| 167 | + imagePickerVc.allowPickingVideo = NO; | |
| 168 | + | |
| 169 | + [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 170 | + UIImage *image = photos.firstObject; | |
| 171 | + if (image) { | |
| 154 | 172 | |
| 155 | - | |
| 156 | - }]; | |
| 173 | + NSLog(@"发送的图过大 = %@",image); | |
| 174 | + } | |
| 175 | + | |
| 157 | 176 | |
| 158 | - [self presentViewController:imagePickerVc animated:YES completion:nil]; | |
| 177 | + | |
| 178 | + }]; | |
| 179 | + [self presentViewController:imagePickerVc animated:YES completion:nil]; | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 159 | 183 | |
| 160 | 184 | } |
| 161 | 185 | ... | ... |