CNLiveUploadVoucher.m
19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
//
// CNLiveUploadVoucher.m
// CNLiveMyOrderModule
//
// Created by 殷巧娟 on 2019/11/21.
//
#import "CNLiveUploadVoucher.h"
//#import <CNLiveImagePickerController/TZImagePickerController.h>
//#import "TZImageManager.h"
//#import "LxGridViewFlowLayout.h"
//#import "TZTestCell.h"
//#import <AssetsLibrary/AssetsLibrary.h>
//#import <Photos/Photos.h>
//#import <YYKit/YYKit.h>
//#import "CNImagePickerController.h"
//#import "CNLiveBaseKit.h"
//#import <QMUIKit/QMUIKit.h>
//#import <Masonry/Masonry.h>
//#import "CNLiveCommonCategory.h"
@interface CNLiveUploadVoucher ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UIActionSheetDelegate>{
}
//@property (nonatomic, strong) UIImagePickerController *imagePickerVc;
//
//@property (nonatomic, strong) UILabel *titleLab;
//@property (nonatomic, strong) UICollectionView *collectionView;
//@property (nonatomic, strong) LxGridViewFlowLayout *layout;
//@property (nonatomic, strong) CLLocation *location;
//@property (nonatomic, strong) NSMutableArray *selectedPhotos;
//@property (nonatomic, strong) NSMutableArray *selectedAssets;
//@property (nonatomic, assign) BOOL isSelectOriginalPhoto;
//@property (nonatomic, assign) CGFloat itemWH;
//@property (nonatomic, assign) CGFloat margin;
//@property (nonatomic, assign) CGFloat collHeight;
//@property (nonatomic, assign) CGFloat add; //是否隐藏加号
//@property (nonatomic, assign) CGFloat colTop; //collectionView 距离顶部坐标
@end
@implementation CNLiveUploadVoucher
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)dealloc
{
NSLog(@"CNUploadVoucher dealloc");
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
// _add = 1;
// _selectedPhotos = [[NSMutableArray alloc] init];
// _selectedAssets = [[NSMutableArray alloc] init];
[self configCollectionView];
}
return self;
}
#pragma mark - 添加collectionView
- (void)configCollectionView {
// 如不需要长按排序效果,将LxGridViewFlowLayout类改成UICollectionViewFlowLayout即可
// _layout = [[LxGridViewFlowLayout alloc] init];
// _margin = 8;
// _itemWH = (KScreenWidth - 20 - 2 * _margin - 4) / 3 - _margin;
// _layout.itemSize = CGSizeMake(_itemWH, _itemWH);
// _layout.minimumInteritemSpacing = _margin;
// _layout.minimumLineSpacing = _margin;
// _colTop = 20;
// if (self.titleLabel) {
// _colTop += self.titleLabel.height+15;
// [self addSubview:self.titleLabel];
// }
// _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, _colTop, KScreenWidth-20, _itemWH+10) collectionViewLayout:_layout];
// _collectionView.alwaysBounceVertical = YES;
// _collectionView.backgroundColor = [UIColor whiteColor];
// _collectionView.contentInset = UIEdgeInsetsMake(4, 4, 4, 4);
// _collectionView.dataSource = self;
// _collectionView.delegate = self;
// _collectionView.scrollEnabled = NO;
// _collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
// [self addSubview:_collectionView];
// [_collectionView registerClass:[TZTestCell class] forCellWithReuseIdentifier:@"TZTestCell"];
}
#pragma mark - Action
#pragma mark - Action
//- (void)deleteBtnClik:(UIButton *)sender {
// __weak typeof(self) weakSelf = self;
// [_selectedPhotos removeObjectAtIndex:sender.tag];
// [_selectedAssets removeObjectAtIndex:sender.tag];
// [_collectionView performBatchUpdates:^{
// NSIndexPath *indexPath = [NSIndexPath indexPathForItem:sender.tag inSection:0];
// [weakSelf.collectionView deleteItemsAtIndexPaths:@[indexPath]];
// } completion:^(BOOL finished) {
// weakSelf.add = 1;
// [weakSelf updateHeight];
// }];
//
//}
//
//#pragma mark - UICollectionViewdelegate
//
//- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
// return self.selectedPhotos.count + self.add;
//}
//- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// TZTestCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:indexPath];
// cell.videoImageView.hidden = YES;
// cell.gifLable.hidden = YES;
//
// if (indexPath.row == _selectedPhotos.count) {
// cell.imageView.image = [UIImage cnLive_getImageNameWithBundle:@"pj_tianjiazhaopian" bundle:@"CNLiveMyOrderModule.bundle/CNLiveMyOrderModule" targetClass:[self class]];
// cell.deleteBtn.hidden = YES;
// } else {
// cell.imageView.image = _selectedPhotos[indexPath.row];
// cell.asset = _selectedAssets[indexPath.row];
// cell.deleteBtn.hidden = NO;
// }
//
// cell.deleteBtn.tag = indexPath.row;
// [cell.deleteBtn addTarget:self action:@selector(deleteBtnClik:) forControlEvents:UIControlEventTouchUpInside];
// return cell;
//}
//
//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// __weak typeof(self) weakSelf = self;
// if (indexPath.row == _selectedPhotos.count) {
//
// [self createAlertViewTitleArray:@[@"拍照",@"从相册选取"] textColor:KTextBlackColor font:UIFontMake(15) actionBlock:^(UIButton *button, NSInteger didRow) {
//
// switch (didRow) {
// case 0: {
// [self takePhoto];
// }
// break;
//
// case 1: {
// [self pushTZImagePickerController];
// }
// break;
//
// default:
// break;
// }
//
// }];
//
// } else { //预览照片
// CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc] initWithSelectedAssets:_selectedAssets selectedPhotos:_selectedPhotos index:indexPath.row];
// [imagePickerVc configTZImagePicker];
// imagePickerVc.maxImagesCount = 9;
// imagePickerVc.allowPickingGif = NO;
// imagePickerVc.allowPickingOriginalPhoto = YES;
// imagePickerVc.allowPickingMultipleVideo = NO;
// imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
// [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
// weakSelf.selectedPhotos = [NSMutableArray arrayWithArray:photos];
// weakSelf.selectedAssets = [NSMutableArray arrayWithArray:assets];
// weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
// [weakSelf.collectionView reloadData];
// weakSelf.collectionView.contentSize = CGSizeMake(0, ((weakSelf.selectedPhotos.count + 2) / 3 ) * (weakSelf.margin + weakSelf.itemWH));
// }];
// [self.viewController presentViewController:imagePickerVc animated:YES completion:nil];
//
// }
//}
//#pragma mark - LxGridViewDataSource
///// 以下三个方法为长按排序相关代码
//- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath {
// return indexPath.item < _selectedPhotos.count;
//}
//
//- (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath canMoveToIndexPath:(NSIndexPath *)destinationIndexPath {
// return (sourceIndexPath.item < _selectedPhotos.count && destinationIndexPath.item < _selectedPhotos.count);
//}
//
//- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath didMoveToIndexPath:(NSIndexPath *)destinationIndexPath {
// UIImage *image = _selectedPhotos[sourceIndexPath.item];
// [_selectedPhotos removeObjectAtIndex:sourceIndexPath.item];
// [_selectedPhotos insertObject:image atIndex:destinationIndexPath.item];
//
// id asset = _selectedAssets[sourceIndexPath.item];
// [_selectedAssets removeObjectAtIndex:sourceIndexPath.item];
// [_selectedAssets insertObject:asset atIndex:destinationIndexPath.item];
//
// [_collectionView reloadData];
//
// if (self.delegate && [self.delegate respondsToSelector:@selector(updateImages:)]) {
// [self.delegate updateImages:_selectedAssets];
// }
//}
//
//#pragma mark - UIImagePickerController
//- (void)takePhoto {
// AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
// if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && iOS7Later) {
// // 无相机权限 做一个友好的提示
// if (iOS8Later) {
// UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的“设置-隐私-相机“中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];//设置
//
// [alert show];
// }
// } else if (authStatus == AVAuthorizationStatusNotDetermined) {
// // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
// if (iOS7Later) {
// [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
// if (granted) {
// dispatch_sync(dispatch_get_main_queue(), ^{
// [self takePhoto];
// });
// }
// }];
// } else {
// [self takePhoto];
// }
// // 拍照之前还需要检查相册权限
// } else if ([TZImageManager authorizationStatus] == 2) { // 已被拒绝,没有相册权限,将无法保存拍的照片
// if (iOS8Later) {
// UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的“设置-隐私-相册“中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];//设置
// [alert show];
// }
// } else if ([TZImageManager authorizationStatus] == 0) { // 未请求过相册权限
// [[TZImageManager manager] requestAuthorizationWithCompletion:^{
// [self takePhoto];
// }];
// } else {
// [self pushImagePickerController];
// }
//}
//// 调用相机
//- (void)pushImagePickerController {
// UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
// if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
// self.imagePickerVc.sourceType = sourceType;
// if(iOS8Later) {
// _imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
// }
// [self.viewController presentViewController:_imagePickerVc animated:YES completion:nil];
// } else {
// NSLog(@"模拟器中无法打开照相机,请在真机中使用");
// }
//}
//#pragma mark - TZImagePickerController
////- (void)pushTZImagePickerController {
//// CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc]initWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
//// [imagePickerVc configTZImagePicker];//配置
////#pragma mark - 五类个性化设置,这些参数都可以不传,此时会走默认设置
//// imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
////
//// imagePickerVc.selectedAssets = _selectedAssets; //目前已经选中的图片数组
//// imagePickerVc.allowTakePicture = NO; //在内部显示拍照按钮
//// imagePickerVc.allowPickingVideo = NO; //是否允许选择视频
//// imagePickerVc.allowPickingImage = YES; //是否允许选择图片
//// imagePickerVc.allowPickingOriginalPhoto = YES; //选择原图
//// imagePickerVc.allowPickingGif = NO; //选择Gif
//// imagePickerVc.allowPickingMultipleVideo = NO; // 是否可以多选视频
//// imagePickerVc.sortAscendingByModificationDate = YES;//排序
//// imagePickerVc.showSelectBtn = NO;
//// imagePickerVc.allowCrop = NO; //是否允许裁剪
//// imagePickerVc.needCircleCrop = NO; //是否使用圆形裁剪
////
//// // 你可以通过block或者代理,来得到用户选择的照片.
//// [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
////
//// }];
//// [self.viewController presentViewController:imagePickerVc animated:YES completion:nil];
////}
//- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// [picker dismissViewControllerAnimated:YES completion:nil];
// NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
// if ([type isEqualToString:@"public.image"]) {
// TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
// tzImagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
// tzImagePickerVc.sortAscendingByModificationDate = YES;
// [tzImagePickerVc showProgressHUD];
// UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//
// // save photo and get asset / 保存图片,获取到asset
// [[TZImageManager manager] savePhotoWithImage:image location:nil completion:^(NSError *error){
// [tzImagePickerVc hideProgressHUD];
// if (error) {
// [tzImagePickerVc hideProgressHUD];
// NSLog(@"图片保存失败 %@",error);
// } else {
// [[TZImageManager manager] getCameraRollAlbum:NO allowPickingImage:YES needFetchAssets:YES completion:^(TZAlbumModel *model) {
// [[TZImageManager manager] getAssetsFromFetchResult:model.result allowPickingVideo:NO allowPickingImage:YES completion:^(NSArray<TZAssetModel *> *models) {
// [tzImagePickerVc hideProgressHUD];
// TZAssetModel *assetModel = [models firstObject];
// if (tzImagePickerVc.sortAscendingByModificationDate) {
// assetModel = [models lastObject];
// }
//
// [self refreshCollectionViewWithAddedAsset:assetModel.asset image:image];
//
// }];
// }];
// }
// }];
// }
//}
//
//- (void)refreshCollectionViewWithAddedAsset:(id)asset image:(UIImage *)image {
// [_selectedAssets addObject:asset];
// [_selectedPhotos addObject:image];
// [_collectionView reloadData];
//
// if (_selectedPhotos.count == 9) {
// _add = 0;
// } else {
// _add = 1;
// }
//
// [self updateHeight];
//
//}
//- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
// if ([picker isKindOfClass:[UIImagePickerController class]]) {
// [picker dismissViewControllerAnimated:YES completion:nil];
// }
//}
//
//#pragma mark - UIActionSheetDelegate
//
//- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// if (buttonIndex == 0) { // take photo / 去拍照
// [self takePhoto];
// } else if (buttonIndex == 1) {
// [self pushTZImagePickerController];
// }
//}
//
//#pragma mark - UIAlertViewDelegate
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
// if (iOS8Later) {
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
// }
// }
//}
//
//#pragma mark - TZImagePickerControllerDelegate
//- (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker {
// // NSLog(@"cancel");
//}
//
//- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
// _selectedPhotos = [NSMutableArray arrayWithArray:photos];
// _selectedAssets = [NSMutableArray arrayWithArray:assets];
// _isSelectOriginalPhoto = isSelectOriginalPhoto;
//
// if (_selectedPhotos.count == 9) {
// _add = 0;
// } else {
// _add = 1;
// }
//
// [self updateHeight];
//
//}
//
////更新自身高度
//- (void)updateHeight {
//
// NSInteger num = 0;
// if (_selectedAssets.count == 9) {
// num = 9;
// } else {
// num = _selectedAssets.count+1;
// }
//
// NSInteger integer = num/3;
// NSInteger remainder = num%3;
//
// if (remainder > 0) {
// integer += 1;
// }
//
// _collectionView.frame = CGRectMake(10, _colTop, KScreenWidth-20, _itemWH*integer + integer*_margin +10);
// [_collectionView reloadData];
//
// CGFloat h = _collectionView.height + integer*_margin + 60;
// [self mas_updateConstraints:^(MASConstraintMaker *make) {
// make.height.mas_equalTo(h);
// }];
//
// if (self.delegate && [self.delegate respondsToSelector:@selector(updateImages:)]) {
// [self.delegate updateImages:_selectedPhotos];
// }
//
//}
//
//
//// Decide album show or not't
//// 决定相册显示与否
//- (BOOL)isAlbumCanSelect:(NSString *)albumName result:(id)result {
// return YES;
//}
//
//// Decide asset show or not't
//// 决定asset显示与否
//- (BOOL)isAssetCanSelect:(id)asset {
// return YES;
//}
//
//#pragma mark -
//#pragma mark - Getter
//- (UILabel *)titleLab
//{
// if (!_titleLab) {
// _titleLab = [[UILabel alloc] init];
// _titleLab.font = [UIFont systemFontOfSize:15];
// _titleLab.text = @"上传照片";
// }
// return _titleLab;
//}
//
//- (UIImagePickerController *)imagePickerVc {
// if (_imagePickerVc == nil) {
// _imagePickerVc = [[UIImagePickerController alloc] init];
// _imagePickerVc.delegate = self;
// // set appearance / 改变相册选择页的导航栏外观
// if (iOS7Later) {
// _imagePickerVc.navigationBar.barTintColor = self.viewController.navigationController.navigationBar.barTintColor;
// }
// _imagePickerVc.navigationBar.tintColor = self.viewController.navigationController.navigationBar.tintColor;
// UIBarButtonItem *tzBarItem, *BarItem;
// if (iOS9Later) {
// tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
// BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
// } else {
// tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil];
// BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil];
// }
// NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
// [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
//
// }
// return _imagePickerVc;
//}
//
//#pragma clang diagnostic pop
@end