// // Collection_Image.m // 乐销 // // Created by 隋林栋 on 2017/1/9. // Copyright © 2017年 ping. All rights reserved. // #import "Collection_Image.h" #import "CollectionImageCell.h"//cell #import "ImageDetailBigView.h"//detail @interface Collection_Image() @property (nonatomic, strong) XG_AssetModel *placeholderModel; @end @implementation Collection_Image #pragma mark 懒加载 -(NSMutableArray *)assets{ if (!_assets) { _assets = @[self.placeholderModel].mutableCopy; } return _assets; } -(XG_AssetModel *)placeholderModel{ if (!_placeholderModel) { _placeholderModel = [[XG_AssetModel alloc]init]; _placeholderModel.isPlaceholder = YES; } return _placeholderModel; } - (NSMutableArray *)aryPhoto{ if (!_aryPhoto) { _aryPhoto = [NSMutableArray new]; } return _aryPhoto; } - (void)openAlbum{ WEAKSELF [[XG_AssetPickerManager manager] handleAuthorizationWithCompletion:^(XG_AuthorizationStatus aStatus) { if (aStatus == XG_AuthorizationStatusAuthorized) { [weakSelf showAssetPickerController]; }else{ [weakSelf showAlert]; } }]; } - (void)showAssetPickerController{ XG_AssetPickerOptions *options = [[XG_AssetPickerOptions alloc]init]; options.maxAssetsCount = 9; options.videoPickable = false; NSMutableArray *array = self.assets; [array removeLastObject];//去除占位model options.pickedAssetModels = array; XG_AssetPickerController *photoPickerVc = [[XG_AssetPickerController alloc] initWithOptions:options delegate:self]; [GB_Nav pushViewController:photoPickerVc animated:true]; } - (void)showAlert{ ModelBtn * modelDismiss = [ModelBtn modelWithTitle:@"取消" imageName:nil highImageName:nil tag:TAG_LINE color:[UIColor redColor]]; ModelBtn * modelConfirm = [ModelBtn modelWithTitle:@"去设置" imageName:nil highImageName:nil tag:TAG_LINE color:COLOR_BLUE]; modelConfirm.blockClick = ^(void){ //去设置 NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } }; [BaseAlertView initWithTitle:@"" content:@"未开启相册权限,是否去设置中开启?" aryBtnModels:@[modelDismiss,modelConfirm] viewShow:[UIApplication sharedApplication].keyWindow]; } - (void)onDeleteBtnClick:(UIButton *)sender{ /* performBatchUpdates并不会调用代理方法collectionView: cellForItemAtIndexPath, 如果用删除按钮的tag来标识则tag不会更新,所以此处没有用tag */ CollectionImageCell *cell = (CollectionImageCell *)sender.superview.superview; NSIndexPath *indexpath = [self.collectionView indexPathForCell:cell]; [self.collectionView performBatchUpdates:^{ [self.collectionView deleteItemsAtIndexPaths:@[indexpath]]; [self.assets removeObjectAtIndex:indexpath.item]; NSMutableArray *arr = [NSMutableArray array]; for (XG_AssetModel *model in self.assets) { [arr addObject:@(model.isPlaceholder)]; } if (self.assets.count == 8 && (![self.assets containsObject:self.placeholderModel]&&![arr containsObject:@(YES)])) { [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:8 inSection:0]]]; [self.assets addObject:self.placeholderModel]; } } completion:^(BOOL finished) { }]; NSMutableArray *newAssets = self.assets.mutableCopy; NSMutableArray *arr = [NSMutableArray array]; for (int i =0; i *)assets{ NSMutableArray *newAssets = assets.mutableCopy; if (newAssets.count < 9 ) { [newAssets addObject:self.placeholderModel]; } [self.assets removeAllObjects]; [self.assets addObjectsFromArray: newAssets]; NSMutableArray *arr = [NSMutableArray arrayWithCapacity:9]; for (int j = 0; j < 9; j++) { [arr addObject:[NSNull null]]; } NSMutableArray *arru = [NSMutableArray array]; dispatch_queue_t serialQueue=dispatch_queue_create("串行", DISPATCH_QUEUE_SERIAL); dispatch_sync(serialQueue, ^{ for (int i =0; i