IOS select multiple photos or photos from the album, sliding

The two days of the project requires the user to upload multiple pictures, or take pictures in real time, and a number of photos arranged in a row. It took me some time. Now write here. The first wave of

IOS select multiple photos or photos from the album, sliding
show figure.Gif

Photograph:

IOS select multiple photos or photos from the album, sliding
Paste_Image.png

Here to use an open source third party zlphotobrowser on the GitHub, but the has a lot of bug, their own use is not very good, it takes time to change.

Due to the recent work is busy, it is not a step by step to explain, I will write my own code directly in the
ViewController.m

#import "ViewController.h" #import "UIImage+ZLPhotoLib.h" #import "ZLPhoto.h" #import "OneTableViewCell.h" //#import "UIButton+WebCache.h" @interface (ViewController) < UITableViewDelegate, UITableViewDataSource, ZLPhotoPickerBrowserViewControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout> {int; MaxPhotos; / / the number of photos in the album before / / cancel, record the number of photos tagged NSMutableArray *_biaojiArr @property;} (nonatomic, strong) UITableView *tableView @property (nonatomic, strong); NSMutableArray *assets; @property (nonatomic, strong) NSMutableArray *arr; / / @property camera (nonatomic, strong) array ZLCameraViewController *cameraVc; @end @implementation ViewController - (void) viewDidLoad {[super viewDidLoad]; Do any additional setup after loading / the view. self.view.backgroundColor [UIColor = whiteColor]; MaxPhotos = 5; _biaojiArr = [[NSMutableArray alloc] init]; [self subTableView];} - {_tableView = subTableView (void) [[UITableView alloc initWithFrame:self.view.frame]; _tableView.delegate = self; _tableView.dataSource = self; [self.view addSubview:_tableView];} - (NSMutableArray *) assets{if (_assets! = [NSMutableArray) {_assets array]}; return _assets;} - (NSMutableArray * ARR) {if (_arr! = [NSMutableArray) {_arr array]}; return _arr;} - (NSInteger) tableView: (UITableView *) tableView n UmberOfRowsInSection: (NSInteger section) {return 10;} - (UITableViewCell *) tableView: (* UITableView) tableView cellForRowAtIndexPath: (NSIndexPath * indexPath) {static NSString = *cellID @ *cell = "Jiege"; UITableViewCell [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell! = [[UITableViewCell) {cell} alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; if (indexPath.row = = 2) {OneTableViewCell *cell = [[OneTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@ "one"]; cell.selectBtn.backgroundColor = [UIColor blueColor]; [cell.selectBtn addTarget:self action:@selector (diaoyao) forControlEvents:UIControlEventTouchUpInside]; Cell.collectionView.showsHorizontalScrollIndicator = NO; cell.collectionView.delegate = self; cell.collectionView.dataSource = self; return cell;} return cell;} - (NSInteger) numberOfSectionsInCollectionView: (UICollectionView * collectionView) {return 1;} - (NSInteger) collectionView: (UICollectionView *) collectionView numberOfItemsInSection: (NSInteger) section {return self.assets.count;} - (CGSize) collectionView: (UICollectionView *) collectionView layout: (UICollectionViewLayout * collectionViewLayout) sizeForItemAtIndexPath: (NSIndexPath *) indexPath{return CGSizeMake (60, 30);} - (CGFloat) collectionView: (UICollectionView * collectionView) layout: (UICollectionViewLayout * collec) TionViewLayout minimumInteritemSpacingForSectionAtIndex: (NSInteger) section {return 15;} - (UICollectionViewCell *) collectionView: (* UICollectionView) collectionView cellForItemAtIndexPath: (NSIndexPath * indexPath) {UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@ "cellId" forIndexPath:indexPath]; UIImageView *photoView = [[UIImageView alloc] initWithFrame:CGRectMake (0, 0, 60, 30)]; photoView.backgroundColor = [UIColor yellowColor]; [cell.contentView addSubview:photoView]; photoView.tag = indexPath.row+1000; UITapGestureRecognizer = *tap [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector (tapp:)]; photoView.userInteractionEnabled = YES; [photoView a DdGestureRecognizer:tap]; / / create delete button UIImageView *deleteView = [[UIImageView alloc] initWithFrame:CGRectMake (0, 0, 5, 5)]; deleteView.backgroundColor = [UIColor redColor [photoView]; addSubview:deleteView]; deleteView.tag = indexPath.row + 1100; UITapGestureRecognizer = *detap [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector (tapp:)]; deleteView.userInteractionEnabled = YES; [deleteView addGestureRecognizer:detap]; NSLog (5555555=assets = "@%ld" self.assets.count, ZLPhotoAssets); *asset = self.assets[indexPath.row]; / / ZLPhotoAssets *asset = _biaojiArr[indexPath.row]; if ([asset isKindOfClass:[ZLPhotoAssets class]]) {photoView.image = asset.originImage }else; if ([asset isKindOfClass:[UIImage class]]) {photoView.image = (UIImage * asset);}else if ([asset isKindOfClass:[ZLCamera class]]) {photoView.image = [(ZLCamera *) asset photoImage] deleteView.backgroundColor;} = [UIColor redColor]; return cell;} - (void) tapp: (UIGestureRecognizer * tap) {int = index (int) [tap view].tag; if (index = = 1000) {/ / first NSLog (@ "first"); UIImageView *photoView = (UIImageView *) [self.view viewWithTag: index]; ZLPhotoPickerBrowserViewController *browserVc = [[ZLPhotoPickerBrowserViewController alloc] init]; [browserVc showHeadPortrait:photoView] else;} if (index = = 1001) {NSLog (@ second "); } if (index = = 1100) {/ / the first difference NSLog (@ "the first difference"); [self.assets% 1100] [_tableView reloadData]; removeObjectAtIndex:index;}} - (void) handleBtn ZLPhotoPickerViewController *pickerVc = "ZLPhotoPickerViewController {/ / alloc] / / MaxCount / / init]; / / Default = 9, pickerVc.maxCount = 9; / / / / Jump AssetsVc / / pickerVc.status = PickerViewShowStatusCameraRoll; / / Filter: / / PickerPhotoStatusAllVideoAndPhotos, PickerPhotoStatusVideos, PickerPhotoStatusPhotos. / pickerVc.photoStatus = PickerPhotoStatusPhotos; / / Select / / Recoder / / Assets / / Desc / / pickerVc.selectPickers = self.assets; Show Photos, And Suppor Camera / / pickerVc.topShowPhotoPi Cker = YES; / / pickerVc.isShowCamera = YES; / / / / CallBack / / pickerVc.callBack ^ (NSArray< ZLPhotoAssets = *> *status = status.mutableCopy) {/ / self.assets / / [self; / / reloadScrollView]; / / NSLog (@ assets =%ld to complete the extraction of the album, ", self.assets.count); / / [_tableView / / [pickerVc / / reloadData];}; showPickerVc:self]; NSLog (@ 66666=assets =%ld, self.assets.count); / / _biaojiArr [NSMutableArray = arrayWithArray:self.assets]; _biaojiArr = [self.assets mutableCopy]; NSLog (@ _biaoji =%ld, _biaojiArr.count); ZLPhotoPickerViewController *pickerVc = [[ZLPhotoPickerViewController alloc] init]; NSArray *array = [[NSArray alloc] initWithArray:self.assets]; picke RVc.selectPickers = array; pickerVc.maxCount = MaxPhotos; for (ZLPhotoAssets *photo in array if ([photo) {isKindOfClass:[ZLCamera class]]) {pickerVc.maxCount = 1; / / NSLog (@ 333333=assets =%ld, self.assets.count);} else if ([photo isKindOfClass:[ZLPhotoAssets class]]) {[self.assets removeObject:photo]; / / NSLog (@ 22222=assets =%ld, self.assets.count)}; / / NSLog (@ 1111111=assets =%ld, self.assets.count);} if (self.assets.count! = 0) {pickerVc.maxCount} - self.assets.count = MaxPhotos; pickerVc.status = PickerViewShowStatusCameraRoll; / / NSLog (@ 444444=assets =%ld, self.assets.count); [pickerVc showPicke RVc:self]; __weak typeof (self) weakSelf = self; pickerVc.callBack = (NSArray ^ *assets) {/ / [weakSelf.assert removeAllObjects]; [weakSelf.assets addObjectsFromArray:assets]; [weakSelf.tableView reloadData];}; / / accept the cancellation of the observer information [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (notice:) name:@ Tongzhi object:nil];} - (void) notice: (ID) sender{NSLog (@ "% @", sender); _assets = [_biaojiArr mutableCopy]; NSLog (@ _assssss =%ld, _assets.count) - (void);} paizhao {/ / / / / / BOOL isCamera camera is used to determine the [UIImagePickerController = isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]; / / isCam / / if (! Era (@ NSLog) {/ / "no camera"); / / return / / / / / /}; / / UIImagePickerController controller initialization picture selection *imagePicker = [[UIImagePickerController alloc] init]; / / imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; / / set through the camera to select photos / / / / imagePicker.allowsEditing = YES; / / set below the camera when the toolbar is displayed, if you need custom shooting interface, can put the toolbar to hide / / imagePicker.delegate / / [self = self; presentViewController:imagePicker animated:YES completion:nil]; NSLog ("camera @ count =%ld, _cameraVc.maxCount); NSLog (@ asset =%ld, _assets.count); if (_assets.count = > MaxPhotos) { NSLog (@ "the current picture has reached the line");} _cameraVc = [[ZLCameraViewController alloc] init]; / / take the maximum number of _cameraVc.maxCount = MaxPhotos-self.assets.count; __weak typeof (self) weakSelf = self; _cameraVc.callback = ^ (NSArray *cameras) {for (ID object in cameras) {[weakSelf.assets addObject:object];} / / [weakSelf.assets addObjectsFromArray:cameras]; [weakSelf.tableView reloadData];}; [_cameraVc showPickerVc:self];} - (void diaoyao) {/ / called album or take a picture of UIAlertController *alert [UIAlertController alertControllerWithTitle:@ = "select get picture operation" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAct Ion *photos = [UIAlertAction actionWithTitle:@ "from the album" style:UIAlertActionStyleDefault handler:^ (UIAlertAction * _Nonnull action) {[self handleBtn]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@}]; cancel style: (UIAlertAction * _Nonnull UIAlertActionStyleCancel handler:^ action) {UIAlertAction *makePhotos = [UIAlertAction actionWithTitle:@}]; "pictures" (UIAlertAction * _Nonnull style:UIAlertActionStyleDefault handler:^ action) {[self paizhao];}]; [alert addA

Which is used in the collectionView, is our custom cell inside

Static NSString *const cellId = "cellId"; static NSString @ *const @ headerId = "headerId"; static NSString *const @ footerId = "footerId"; - (UICollectionView * collectionView) {if (! _collectionView) {UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; _collectionView = "UICollectionView alloc initWithFrame:CGRectMake" (80, 10 self.frame.size.width, 80, 30) collectionViewLayout: layout] = [UIColor; _collectionView.backgroundColor whiteColor]; [_collectionView registerClass: [UICollectionViewCell class forCellWithReuseIdentifier]] [_collectionView: cellId; registerClass:[UICollectionRe UsableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerId] [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter; withReuseIdentifier:footerId] [self.contentView; addSubview:_collectionView] return _collectionView;}};

Run as follows:

IOS select multiple photos or photos from the album, sliding
test.Gif

If you like, do not forget the point of praise, if help you, do not forget to ask me to eat spicy bar ~ if you do not understand, you can leave a message, I have time to reply ~ for a better tomorrow, sleep.