猎豆优选

QBImagePickerController.m 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // QBImagePickerController.m
  3. // QBImagePicker
  4. //
  5. // Created by Katsuma Tanaka on 2015/04/03.
  6. // Copyright (c) 2015 Katsuma Tanaka. All rights reserved.
  7. //
  8. #import "QBImagePickerController.h"
  9. #import <Photos/Photos.h>
  10. // ViewControllers
  11. #import "QBAlbumsViewController.h"
  12. @interface QBImagePickerController ()
  13. @property (nonatomic, strong) UINavigationController *albumsNavigationController;
  14. @property (nonatomic, strong) NSBundle *assetBundle;
  15. @end
  16. @implementation QBImagePickerController
  17. - (instancetype)init
  18. {
  19. self = [super init];
  20. if (self) {
  21. // Set default values
  22. self.assetCollectionSubtypes = @[
  23. @(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
  24. @(PHAssetCollectionSubtypeAlbumMyPhotoStream),
  25. @(PHAssetCollectionSubtypeSmartAlbumPanoramas),
  26. @(PHAssetCollectionSubtypeSmartAlbumVideos),
  27. @(PHAssetCollectionSubtypeSmartAlbumBursts)
  28. ];
  29. self.minimumNumberOfSelection = 1;
  30. self.numberOfColumnsInPortrait = 4;
  31. self.numberOfColumnsInLandscape = 7;
  32. _selectedAssets = [NSMutableOrderedSet orderedSet];
  33. // Get asset bundle
  34. self.assetBundle = [NSBundle bundleForClass:[self class]];
  35. NSString *bundlePath = [self.assetBundle pathForResource:@"QBImagePicker" ofType:@"bundle"];
  36. if (bundlePath) {
  37. self.assetBundle = [NSBundle bundleWithPath:bundlePath];
  38. }
  39. [self setUpAlbumsViewController];
  40. // Set instance
  41. QBAlbumsViewController *albumsViewController = (QBAlbumsViewController *)self.albumsNavigationController.topViewController;
  42. albumsViewController.imagePickerController = self;
  43. }
  44. return self;
  45. }
  46. - (void)setUpAlbumsViewController
  47. {
  48. // Add QBAlbumsViewController as a child
  49. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"QBImagePicker" bundle:self.assetBundle];
  50. UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"QBAlbumsNavigationController"];
  51. [self addChildViewController:navigationController];
  52. navigationController.view.frame = self.view.bounds;
  53. [self.view addSubview:navigationController.view];
  54. [navigationController didMoveToParentViewController:self];
  55. self.albumsNavigationController = navigationController;
  56. }
  57. @end