TZImagePickerController.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // TZImagePickerController.h
  3. // TZImagePickerController
  4. //
  5. // Created by 谭真 on 15/12/24.
  6. // Copyright © 2015年 谭真. All rights reserved.
  7. // version 1.7.8 - 2016.12.20
  8. /*
  9. 经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右)
  10. 最初发现这个问题并修复的是@小鱼周凌宇同学,她的博客地址: http://zhoulingyu.com/
  11. 表示感谢~
  12. 原来xib确实会导致性能问题啊...大家也要注意了...
  13. */
  14. #import <UIKit/UIKit.h>
  15. #import "TZAssetModel.h"
  16. #import "NSBundle+TZImagePicker.h"
  17. #define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
  18. #define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
  19. #define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
  20. #define iOS9_1Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.1f)
  21. @protocol TZImagePickerControllerDelegate;
  22. @interface TZImagePickerController : UINavigationController
  23. /// Use this init method / 用这个初始化方法
  24. - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount delegate:(id<TZImagePickerControllerDelegate>)delegate;
  25. - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate;
  26. - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate pushPhotoPickerVc:(BOOL)pushPhotoPickerVc;
  27. /// This init method just for previewing photos / 用这个初始化方法以预览图片
  28. - (instancetype)initWithSelectedAssets:(NSMutableArray *)selectedAssets selectedPhotos:(NSMutableArray *)selectedPhotos index:(NSInteger)index;
  29. /// This init method for crop photo / 用这个初始化方法以裁剪图片
  30. - (instancetype)initCropTypeWithAsset:(id)asset photo:(UIImage *)photo completion:(void (^)(UIImage *cropImage,id asset))completion;
  31. /// Default is 9 / 默认最大可选9张图片
  32. @property (nonatomic, assign) NSInteger maxImagesCount;
  33. /// The minimum count photos user must pick, Default is 0
  34. /// 最小照片必选张数,默认是0
  35. @property (nonatomic, assign) NSInteger minImagesCount;
  36. /// Always enale the done button, not require minimum 1 photo be picked
  37. /// 让完成按钮一直可以点击,无须最少选择一张图片
  38. @property (nonatomic, assign) BOOL alwaysEnableDoneBtn;
  39. /// Sort photos ascending by modificationDate,Default is YES
  40. /// 对照片排序,按修改时间升序,默认是YES。如果设置为NO,最新的照片会显示在最前面,内部的拍照按钮会排在第一个
  41. @property (nonatomic, assign) BOOL sortAscendingByModificationDate;
  42. /// Default is 828px / 默认828像素宽
  43. @property (nonatomic, assign) CGFloat photoWidth;
  44. /// Default is 600px / 默认600像素宽
  45. @property (nonatomic, assign) CGFloat photoPreviewMaxWidth;
  46. /// Default is 15, While fetching photo, HUD will dismiss automatic if timeout;
  47. /// 超时时间,默认为15秒,当取图片时间超过15秒还没有取成功时,会自动dismiss HUD;
  48. @property (nonatomic, assign) NSInteger timeout;
  49. /// Default is YES, if set NO, the original photo button will hide. user can't picking original photo.
  50. /// 默认为YES,如果设置为NO,原图按钮将隐藏,用户不能选择发送原图
  51. @property (nonatomic, assign) BOOL allowPickingOriginalPhoto;
  52. /// Default is YES, if set NO, user can't picking video.
  53. /// 默认为YES,如果设置为NO,用户将不能选择视频
  54. @property (nonatomic, assign) BOOL allowPickingVideo;
  55. /// Default is NO, if set YES, user can picking gif image.
  56. /// 默认为NO,如果设置为YES,用户可以选择gif图片
  57. @property (nonatomic, assign) BOOL allowPickingGif;
  58. /// Default is YES, if set NO, user can't picking image.
  59. /// 默认为YES,如果设置为NO,用户将不能选择发送图片
  60. @property(nonatomic, assign) BOOL allowPickingImage;
  61. /// Default is YES, if set NO, user can't take picture.
  62. /// 默认为YES,如果设置为NO,拍照按钮将隐藏,用户将不能选择照片
  63. @property(nonatomic, assign) BOOL allowTakePicture;
  64. /// Default is YES, if set NO, user can't preview photo.
  65. /// 默认为YES,如果设置为NO,预览按钮将隐藏,用户将不能去预览照片
  66. @property (nonatomic, assign) BOOL allowPreview;
  67. /// Default is YES, if set NO, the picker don't dismiss itself.
  68. /// 默认为YES,如果设置为NO, 选择器将不会自己dismiss
  69. @property(nonatomic, assign) BOOL autoDismiss;
  70. /// The photos user have selected
  71. /// 用户选中过的图片数组
  72. @property (nonatomic, strong) NSMutableArray *selectedAssets;
  73. @property (nonatomic, strong) NSMutableArray<TZAssetModel *> *selectedModels;
  74. /// Minimum selectable photo width, Default is 0
  75. /// 最小可选中的图片宽度,默认是0,小于这个宽度的图片不可选中
  76. @property (nonatomic, assign) NSInteger minPhotoWidthSelectable;
  77. @property (nonatomic, assign) NSInteger minPhotoHeightSelectable;
  78. /// Hide the photo what can not be selected, Default is NO
  79. /// 隐藏不可以选中的图片,默认是NO,不推荐将其设置为YES
  80. @property (nonatomic, assign) BOOL hideWhenCanNotSelect;
  81. /// Single selection mode, valid when maxImagesCount = 1
  82. /// 单选模式,maxImagesCount为1时才生效
  83. @property (nonatomic, assign) BOOL showSelectBtn; ///< 在单选模式下,照片列表页中,显示选择按钮,默认为NO
  84. @property (nonatomic, assign) BOOL allowCrop; ///< 允许裁剪,默认为YES,showSelectBtn为NO才生效
  85. @property (nonatomic, assign) CGRect cropRect; ///< 裁剪框的尺寸
  86. @property (nonatomic, assign) BOOL needCircleCrop; ///< 需要圆形裁剪框
  87. @property (nonatomic, assign) NSInteger circleCropRadius; ///< 圆形裁剪框半径大小
  88. @property (nonatomic, copy) void (^cropViewSettingBlock)(UIView *cropView); ///< 自定义裁剪框的其他属性
  89. - (void)showAlertWithTitle:(NSString *)title;
  90. - (void)showProgressHUD;
  91. - (void)hideProgressHUD;
  92. @property (nonatomic, assign) BOOL isSelectOriginalPhoto;
  93. @property (nonatomic, copy) NSString *takePictureImageName;
  94. @property (nonatomic, copy) NSString *photoSelImageName;
  95. @property (nonatomic, copy) NSString *photoDefImageName;
  96. @property (nonatomic, copy) NSString *photoOriginSelImageName;
  97. @property (nonatomic, copy) NSString *photoOriginDefImageName;
  98. @property (nonatomic, copy) NSString *photoPreviewOriginDefImageName;
  99. @property (nonatomic, copy) NSString *photoNumberIconImageName;
  100. /// Appearance / 外观颜色 + 按钮文字
  101. @property (nonatomic, strong) UIColor *oKButtonTitleColorNormal;
  102. @property (nonatomic, strong) UIColor *oKButtonTitleColorDisabled;
  103. @property (nonatomic, strong) UIColor *barItemTextColor;
  104. @property (nonatomic, strong) UIFont *barItemTextFont;
  105. @property (nonatomic, copy) NSString *doneBtnTitleStr;
  106. @property (nonatomic, copy) NSString *cancelBtnTitleStr;
  107. @property (nonatomic, copy) NSString *previewBtnTitleStr;
  108. @property (nonatomic, copy) NSString *fullImageBtnTitleStr;
  109. @property (nonatomic, copy) NSString *settingBtnTitleStr;
  110. @property (nonatomic, copy) NSString *processHintStr;
  111. /// Public Method
  112. - (void)cancelButtonClick;
  113. // The picker should dismiss itself; when it dismissed these handle will be called.
  114. // You can also set autoDismiss to NO, then the picker don't dismiss itself.
  115. // If isOriginalPhoto is YES, user picked the original photo.
  116. // You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
  117. // The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
  118. // 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的handle
  119. // 你也可以设置autoDismiss属性为NO,选择器就不会自己dismis了
  120. // 如果isSelectOriginalPhoto为YES,表明用户选择了原图
  121. // 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
  122. // photos数组里的UIImage对象,默认是828像素宽,你可以通过设置photoWidth属性的值来改变它
  123. @property (nonatomic, copy) void (^didFinishPickingPhotosHandle)(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto);
  124. @property (nonatomic, copy) void (^didFinishPickingPhotosWithInfosHandle)(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto,NSArray<NSDictionary *> *infos);
  125. @property (nonatomic, copy) void (^imagePickerControllerDidCancelHandle)();
  126. // If user picking a video, this handle will be called.
  127. // If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
  128. // 如果用户选择了一个视频,下面的handle会被执行
  129. // 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象
  130. @property (nonatomic, copy) void (^didFinishPickingVideoHandle)(UIImage *coverImage,id asset);
  131. // If user picking a gif image, this callback will be called.
  132. // 如果用户选择了一个gif图片,下面的handle会被执行
  133. @property (nonatomic, copy) void (^didFinishPickingGifImageHandle)(UIImage *animatedImage,id sourceAssets);
  134. @property (nonatomic, weak) id<TZImagePickerControllerDelegate> pickerDelegate;
  135. @end
  136. @protocol TZImagePickerControllerDelegate <NSObject>
  137. @optional
  138. // The picker should dismiss itself; when it dismissed these handle will be called.
  139. // You can also set autoDismiss to NO, then the picker don't dismiss itself.
  140. // If isOriginalPhoto is YES, user picked the original photo.
  141. // You can get original photo with asset, by the method [[TZImageManager manager] getOriginalPhotoWithAsset:completion:].
  142. // The UIImage Object in photos default width is 828px, you can set it by photoWidth property.
  143. // 这个照片选择器会自己dismiss,当选择器dismiss的时候,会执行下面的handle
  144. // 你也可以设置autoDismiss属性为NO,选择器就不会自己dismis了
  145. // 如果isSelectOriginalPhoto为YES,表明用户选择了原图
  146. // 你可以通过一个asset获得原图,通过这个方法:[[TZImageManager manager] getOriginalPhotoWithAsset:completion:]
  147. // photos数组里的UIImage对象,默认是828像素宽,你可以通过设置photoWidth属性的值来改变它
  148. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto;
  149. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos;
  150. - (void)imagePickerControllerDidCancel:(TZImagePickerController *)picker __attribute__((deprecated("Use -tz_imagePickerControllerDidCancel:.")));
  151. - (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker;
  152. // If user picking a video, this callback will be called.
  153. // If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
  154. // 如果用户选择了一个视频,下面的handle会被执行
  155. // 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象
  156. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(id)asset;
  157. // If user picking a gif image, this callback will be called.
  158. // 如果用户选择了一个gif图片,下面的handle会被执行
  159. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(id)asset;
  160. @end
  161. @interface TZAlbumPickerController : UIViewController
  162. @property (nonatomic, assign) NSInteger columnNumber;
  163. @end
  164. @interface UIImage (MyBundle)
  165. + (UIImage *)imageNamedFromMyBundle:(NSString *)name;
  166. @end