| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- //
- // DKPhotoPickerGroupViewController.m
- // DKAssetsPickerDemo
- // Copyright (c) 2014年 com.zixue101.www. All rights reserved.
- //
- #define CELL_ROW 4
- #define CELL_MARGIN 5
- #define CELL_LINE_MARGIN 5
- #import "DKPhotoPickerGroupViewController.h"
- #import "DKPhotoPickerCollectionView.h"
- #import "DKPhotoPickerDatas.h"
- #import "DKPhotoPickerGroupViewController.h"
- #import "DKPhotoPickerGroup.h"
- #import "DKPhotoPickerGroupTableViewCell.h"
- #import "DKPhotoPickerAssetsViewController.h"
- #import <AssetsLibrary/AssetsLibrary.h>
- @interface DKPhotoPickerGroupViewController () <UITableViewDataSource,UITableViewDelegate>
- @property (nonatomic , weak) DKPhotoPickerAssetsViewController *collectionVc;
- @property (nonatomic , weak) UITableView *tableView;
- @property (nonatomic , strong) NSArray *groups;
- @end
- @implementation DKPhotoPickerGroupViewController
- - (UITableView *)tableView{
- if (!_tableView) {
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- tableView.translatesAutoresizingMaskIntoConstraints = NO;
- tableView.delegate = self;
- [self.view addSubview:tableView];
- self.tableView = tableView;
-
- NSDictionary *views = NSDictionaryOfVariableBindings(tableView);
-
- NSString *heightVfl = @"V:|-0-[tableView]-0-|";
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:heightVfl options:0 metrics:nil views:views]];
- NSString *widthVfl = @"H:|-0-[tableView]-0-|";
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:widthVfl options:0 metrics:nil views:views]];
-
- }
- return _tableView;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self tableView];
-
- // 设置按钮
- [self setupButtons];
-
- // 获取图片
- [self getImgs];
-
- self.title = @"选择相册";
-
- }
- - (void) setupButtons{
- UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStyleDone target:self action:@selector(back)];
-
- self.navigationItem.rightBarButtonItem = barItem;
- }
- #pragma mark - <UITableViewDataSource>
- - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.groups.count;
- }
- - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- DKPhotoPickerGroupTableViewCell *cell = [DKPhotoPickerGroupTableViewCell instanceCell];
-
- cell.group = self.groups[indexPath.row];
-
- return cell;
-
- }
- #pragma mark 跳转到控制器里面的内容
- - (void) jump2StatusVc{
- // 如果是相册
- DKPhotoPickerGroup *gp = nil;
- for (DKPhotoPickerGroup *group in self.groups) {
- if ((self.status == PickerViewShowStatusCameraRoll || self.status == PickerViewShowStatusVideo) && ([group.groupName isEqualToString:@"Camera Roll"] || [group.groupName isEqualToString:@"相机胶卷"])) {
- gp = group;
- break;
- }else if (self.status == PickerViewShowStatusSavePhotos && ([group.groupName isEqualToString:@"Saved Photos"] || [group.groupName isEqualToString:@"保存相册"])){
- gp = group;
- break;
- }else if (self.status == PickerViewShowStatusPhotoStream && ([group.groupName isEqualToString:@"Stream"] || [group.groupName isEqualToString:@"我的照片流"])){
- gp = group;
- break;
- }
- }
-
- if (!gp) return ;
-
- DKPhotoPickerAssetsViewController *assetsVc = [[DKPhotoPickerAssetsViewController alloc] init];
- assetsVc.cameraCount=self.cameraCount;
- assetsVc.selectPickerAssets = self.selectAsstes;
- assetsVc.assetsGroup = gp;
- assetsVc.groupVc = self;
- assetsVc.minCount = self.minCount;
- [self.navigationController pushViewController:assetsVc animated:NO];
- }
- #pragma mark -<UITableViewDelegate>
- - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 80;
- }
- - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- DKPhotoPickerGroup *group = self.groups[indexPath.row];
- DKPhotoPickerAssetsViewController *assetsVc = [[DKPhotoPickerAssetsViewController alloc] init];
- assetsVc.cameraCount=self.cameraCount;
- assetsVc.selectPickerAssets = self.selectAsstes;
- assetsVc.groupVc = self;
- assetsVc.assetsGroup = group;
- assetsVc.minCount = self.minCount;
- [self.navigationController pushViewController:assetsVc animated:YES];
- }
- #pragma mark -<Images Datas>
- -(void)getImgs{
- DKPhotoPickerDatas *datas = [DKPhotoPickerDatas defaultPicker];
-
- __weak typeof(self) weakSelf = self;
-
- if (self.status == PickerViewShowStatusVideo){
- // 获取所有的图片URLs
- [datas getAllGroupWithVideos:^(NSArray *groups) {
- self.groups = groups;
- if (self.status) {
- [self jump2StatusVc];
- }
-
- weakSelf.tableView.dataSource = self;
- [weakSelf.tableView reloadData];
-
- }];
-
- }else{
- // 获取所有的图片URLs
- [datas getAllGroupWithPhotos:^(NSArray *groups) {
- self.groups = groups;
- if (self.status) {
- [self jump2StatusVc];
- }
-
- weakSelf.tableView.dataSource = self;
- [weakSelf.tableView reloadData];
-
- }];
- }
- }
- #pragma mark -<Navigation Actions>
- - (void) back{
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- @end
|