DKPhotoPickerViewController.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // PickerViewController.m
  3. // DKAssetsPickerDemo
  4. //
  5. // Copyright (c) 2014年 com.zixue101.www. All rights reserved.
  6. //
  7. #import "DKPhotoPickerViewController.h"
  8. #import "DKPhoto.h"
  9. @interface DKPhotoPickerViewController ()
  10. @property (nonatomic , weak) DKPhotoPickerGroupViewController *groupVc;
  11. @end
  12. @implementation DKPhotoPickerViewController
  13. #pragma mark - Life cycle
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.view.backgroundColor = [UIColor whiteColor];
  17. [self addNotification];
  18. }
  19. - (void)dealloc{
  20. [[NSNotificationCenter defaultCenter] removeObserver:self];
  21. }
  22. #pragma mark - init Action
  23. - (void) createNavigationController{
  24. DKPhotoPickerGroupViewController *groupVc = [[DKPhotoPickerGroupViewController alloc] init];
  25. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:groupVc];
  26. nav.view.frame = self.view.bounds;
  27. [self addChildViewController:nav];
  28. [self.view addSubview:nav.view];
  29. self.groupVc = groupVc;
  30. }
  31. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  32. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  33. [self createNavigationController];
  34. }
  35. return self;
  36. }
  37. - (void)setSelectPickers:(NSArray *)selectPickers{
  38. _selectPickers = selectPickers;
  39. self.groupVc.selectAsstes = selectPickers;
  40. }
  41. -(void)setCameraCount:(NSInteger)cameraCount{
  42. _cameraCount=cameraCount;
  43. self.groupVc.cameraCount=cameraCount;
  44. }
  45. - (void)setStatus:(PickerViewShowStatus)status{
  46. _status = status;
  47. self.groupVc.status = status;
  48. }
  49. - (void)setMinCount:(NSInteger)minCount{
  50. if (minCount <= 0) return;
  51. _minCount = minCount;
  52. self.groupVc.minCount = minCount;
  53. }
  54. #pragma mark - 展示控制器
  55. - (void)show{
  56. [[[[UIApplication sharedApplication].windows firstObject] rootViewController] presentViewController:self animated:YES completion:nil];
  57. }
  58. - (void) addNotification{
  59. // 监听异步done通知
  60. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  61. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(done:) name:PICKER_TAKE_DONE object:nil];
  62. });
  63. }
  64. - (void) done:(NSNotification *)note{
  65. NSArray *selectArray = note.userInfo[@"selectAssets"];
  66. dispatch_async(dispatch_get_main_queue(), ^{
  67. if ([self.delegate respondsToSelector:@selector(pickerViewControllerDoneAsstes:)]) {
  68. [self.delegate pickerViewControllerDoneAsstes:selectArray];
  69. }else if (self.callBack){
  70. self.callBack(selectArray);
  71. }
  72. [self dismissViewControllerAnimated:YES completion:nil];
  73. });
  74. }
  75. - (void)setDelegate:(id<DKPhotoPickerViewControllerDelegate>)delegate{
  76. _delegate = delegate;
  77. self.groupVc.delegate = delegate;
  78. }
  79. @end