// // PickerViewController.m // DKAssetsPickerDemo // // Copyright (c) 2014年 com.zixue101.www. All rights reserved. // #import "DKPhotoPickerViewController.h" #import "DKPhoto.h" @interface DKPhotoPickerViewController () @property (nonatomic , weak) DKPhotoPickerGroupViewController *groupVc; @end @implementation DKPhotoPickerViewController #pragma mark - Life cycle - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [self addNotification]; } - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - init Action - (void) createNavigationController{ DKPhotoPickerGroupViewController *groupVc = [[DKPhotoPickerGroupViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:groupVc]; nav.view.frame = self.view.bounds; [self addChildViewController:nav]; [self.view addSubview:nav.view]; self.groupVc = groupVc; } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { [self createNavigationController]; } return self; } - (void)setSelectPickers:(NSArray *)selectPickers{ _selectPickers = selectPickers; self.groupVc.selectAsstes = selectPickers; } -(void)setCameraCount:(NSInteger)cameraCount{ _cameraCount=cameraCount; self.groupVc.cameraCount=cameraCount; } - (void)setStatus:(PickerViewShowStatus)status{ _status = status; self.groupVc.status = status; } - (void)setMinCount:(NSInteger)minCount{ if (minCount <= 0) return; _minCount = minCount; self.groupVc.minCount = minCount; } #pragma mark - 展示控制器 - (void)show{ [[[[UIApplication sharedApplication].windows firstObject] rootViewController] presentViewController:self animated:YES completion:nil]; } - (void) addNotification{ // 监听异步done通知 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(done:) name:PICKER_TAKE_DONE object:nil]; }); } - (void) done:(NSNotification *)note{ NSArray *selectArray = note.userInfo[@"selectAssets"]; dispatch_async(dispatch_get_main_queue(), ^{ if ([self.delegate respondsToSelector:@selector(pickerViewControllerDoneAsstes:)]) { [self.delegate pickerViewControllerDoneAsstes:selectArray]; }else if (self.callBack){ self.callBack(selectArray); } [self dismissViewControllerAnimated:YES completion:nil]; }); } - (void)setDelegate:(id)delegate{ _delegate = delegate; self.groupVc.delegate = delegate; } @end