HXPhotoDefine.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // HXPhotoDefine.h
  3. // HXPhotoPickerExample
  4. //
  5. // Created by Silence on 2017/11/24.
  6. // Copyright © 2017年 Silence. All rights reserved.
  7. //
  8. #ifndef HXPhotoDefine_h
  9. #define HXPhotoDefine_h
  10. #import <CommonCrypto/CommonDigest.h>
  11. #import "NSBundle+HXPhotoPicker.h"
  12. /// 当前版本
  13. #define HXVersion @"3.3.2"
  14. // 日志输出
  15. #ifdef DEBUG
  16. #define NSSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
  17. #else
  18. #define NSSLog(...)
  19. #endif
  20. /// 如果想要HXPhotoView的item大小自定义设置,请修改为 1
  21. /// 如果为pod导入的话,请使用 pod 'HXPhotoPicker/CustomItem'
  22. /// 并且实现HXPhotoView的代理
  23. /// - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath isAddItem:(BOOL)isAddItem photoView:(HXPhotoView *)photoView
  24. /// 如果不实现此代理,item的小大将默认 (100, 100)
  25. #define HXPhotoViewCustomItemSize 0
  26. #define HXRound(x) (round(x*100000)/100000)
  27. #define HXRoundHundreds(x) (round(x*100)/100)
  28. #define HXRoundDecade(x) (round(x*10)/10)
  29. #define HXRoundFrame(rect) CGRectMake(HXRound(rect.origin.x), HXRound(rect.origin.y), HXRound(rect.size.width), HXRound(rect.size.height))
  30. #define HXRoundFrameHundreds(rect) CGRectMake(HXRoundHundreds(rect.origin.x), HXRoundHundreds(rect.origin.y), HXRoundHundreds(rect.size.width), HXRoundHundreds(rect.size.height))
  31. #define HXEncodeKey @"HXModelArray"
  32. #define HXCameraImageKey @"HXCameraImageURLKey"
  33. #define HXPhotoPickerLibraryCaches [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
  34. #define HXPhotoPickerDocuments [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
  35. //#define HXPhotoPickerLocalModelsPath [HXPhotoPickerDocuments stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/localModels", HXPhotoHeaderSearchPath]]
  36. #define HXPhotoPickerLocalModelsPath [HXPhotoPickerLibraryCaches stringByAppendingPathComponent:@"localModels"]
  37. #define HXPhotoHeaderSearchPath @"com.silence.hxphotopicker"
  38. #define HXPhotoPickerAssetCachesPath [HXPhotoPickerLibraryCaches stringByAppendingPathComponent:HXPhotoHeaderSearchPath]
  39. #define HXPhotoPickerCachesDownloadPath [HXPhotoPickerAssetCachesPath stringByAppendingPathComponent:@"download"]
  40. #define HXPhotoPickerDownloadVideosPath [HXPhotoPickerCachesDownloadPath stringByAppendingPathComponent:@"videos"]
  41. #define HXPhotoPickerDownloadPhotosPath [HXPhotoPickerCachesDownloadPath stringByAppendingPathComponent:@"photos"]
  42. #define HXPhotoPickerCachesLivePhotoPath [HXPhotoPickerAssetCachesPath stringByAppendingPathComponent:@"LivePhoto"]
  43. #define HXPhotoPickerLivePhotoVideosPath [HXPhotoPickerCachesLivePhotoPath stringByAppendingPathComponent:@"videos"]
  44. #define HXPhotoPickerLivePhotoImagesPath [HXPhotoPickerCachesLivePhotoPath stringByAppendingPathComponent:@"images"]
  45. #define HXShowLog NO
  46. #define HX_UI_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  47. #define HX_ALLOW_LOCATION ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] || [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"])
  48. #define HX_PREFERS_STATUS_BAR_HIDDEN [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue]
  49. #define HasAFNetworking (__has_include(<AFNetworking/AFNetworking.h>) || __has_include("AFNetworking.h"))
  50. #define HasYYWebImage (__has_include(<YYWebImage/YYWebImage.h>) || __has_include("YYWebImage.h"))
  51. #define HasYYKit (__has_include(<YYKit/YYKit.h>) || __has_include("YYKit.h"))
  52. #define HasYYKitOrWebImage (__has_include(<YYWebImage/YYWebImage.h>) || __has_include("YYWebImage.h") || __has_include(<YYKit/YYKit.h>) || __has_include("YYKit.h"))
  53. #define HasSDWebImage (__has_include(<SDWebImage/UIImageView+WebCache.h>) || __has_include("UIImageView+WebCache.h"))
  54. #define HX_ScreenWidth [UIScreen mainScreen].bounds.size.width
  55. #define HX_ScreenHeight [UIScreen mainScreen].bounds.size.height
  56. #define HX_IS_IPHONEX (CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(375, 812)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(812, 375)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(414, 896)) || CGSizeEqualToSize([UIScreen mainScreen].bounds.size, CGSizeMake(896, 414)))
  57. // 判断iPhone X
  58. #define HX_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
  59. //判断iPHoneXr
  60. #define HX_Is_iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  61. //判断iPHoneXs
  62. #define HX_Is_iPhoneXS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  63. //判断iPhoneXs Max
  64. #define HX_Is_iPhoneXS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  65. //判断iPHone12 mini
  66. #define HX_Is_iPhoneTwelveMini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  67. //判断iPHone12 和 iPHone12 Pro
  68. #define HX_Is_iPhoneTwelvePro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  69. //判断iPHone12 ProMax
  70. #define HX_Is_iPhoneTwelveProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  71. #define HX_Is_iPhone14ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1290, 2796), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  72. #define HX_Is_iPhone14Pro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1179, 2556), [[UIScreen mainScreen] currentMode].size) && !HX_UI_IS_IPAD : NO)
  73. #define HX_IS_IPhoneX_All (HX_Is_iPhoneX || HX_Is_iPhoneXR || HX_Is_iPhoneXS || HX_Is_iPhoneXS_MAX || HX_IS_IPHONEX || HX_Is_iPhoneTwelveMini || HX_Is_iPhoneTwelvePro || HX_Is_iPhoneTwelveProMax || HX_Is_iPhone14Pro || HX_Is_iPhone14ProMax)
  74. // 导航栏 + 状态栏 的高度
  75. #define hxNavigationBarHeight ((HX_UI_IS_IPAD ? 50 : 44) + HXStatusBarHeight)
  76. #define hxTopMargin (HX_IS_IPhoneX_All ? 44 : 0)
  77. #define hxBottomMargin (HX_IS_IPhoneX_All ? 34 : 0)
  78. #define HXStatusBarHeight [HXPhotoTools getStatusBarHeight]
  79. #define HX_IOS14_Later ([UIDevice currentDevice].systemVersion.floatValue >= 14.0f)
  80. #define HX_IOS13_Later ([UIDevice currentDevice].systemVersion.floatValue >= 13.0f)
  81. #define HX_IOS11_Later ([UIDevice currentDevice].systemVersion.floatValue >= 11.0f)
  82. #define HX_IOS11_Earlier ([UIDevice currentDevice].systemVersion.floatValue < 11.0f)
  83. #define HX_IOS10_Later ([UIDevice currentDevice].systemVersion.floatValue >= 10.0f)
  84. #define HX_IOS91Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.1f)
  85. #define HX_IOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
  86. #define HX_IOS82Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.2f)
  87. #define HX_IOS9Earlier ([UIDevice currentDevice].systemVersion.floatValue < 9.0f)
  88. // 弱引用
  89. #define HXWeakSelf __weak typeof(self) weakSelf = self;
  90. // 强引用
  91. #define HXStrongSelf __strong typeof(weakSelf) strongSelf = weakSelf;
  92. #pragma mark - Hash
  93. #define HX_MAX_FILE_EXTENSION_LENGTH (NAME_MAX - CC_MD5_DIGEST_LENGTH * 2 - 1)
  94. #pragma clang diagnostic push
  95. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  96. static inline NSString * _Nonnull HXDiskCacheFileNameForKey(NSString * _Nullable key, BOOL addExt) {
  97. const char *str = key.UTF8String;
  98. if (str == NULL) {
  99. str = "";
  100. }
  101. unsigned char r[CC_MD5_DIGEST_LENGTH];
  102. CC_MD5(str, (CC_LONG)strlen(str), r);
  103. NSURL *keyURL = [NSURL URLWithString:key];
  104. NSString *ext = keyURL ? keyURL.pathExtension : key.pathExtension;
  105. // File system has file name length limit, we need to check if ext is too long, we don't add it to the filename
  106. if (ext.length > HX_MAX_FILE_EXTENSION_LENGTH) {
  107. ext = nil;
  108. }
  109. NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  110. r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
  111. r[11], r[12], r[13], r[14], r[15]];
  112. if (addExt) {
  113. filename = [filename stringByAppendingFormat:@"%@", ext.length == 0 ? @"" : [NSString stringWithFormat:@".%@", ext]];
  114. }
  115. return filename;
  116. }
  117. #pragma clang diagnostic pop
  118. CG_INLINE UIAlertController * _Nullable hx_showAlert(UIViewController * _Nullable vc,
  119. NSString * _Nullable title,
  120. NSString * _Nullable message,
  121. NSString * _Nullable buttonTitle1,
  122. NSString * _Nullable buttonTitle2,
  123. dispatch_block_t _Nullable buttonTitle1Handler,
  124. dispatch_block_t _Nullable buttonTitle2Handler) {
  125. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
  126. message:message
  127. preferredStyle:UIAlertControllerStyleAlert];
  128. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
  129. UIPopoverPresentationController *pop = [alertController popoverPresentationController];
  130. pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
  131. pop.sourceView = vc.view;
  132. pop.sourceRect = vc.view.bounds;
  133. }
  134. if (buttonTitle1) {
  135. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:buttonTitle1
  136. style:UIAlertActionStyleCancel
  137. handler:^(UIAlertAction * _Nonnull action) {
  138. if (buttonTitle1Handler) buttonTitle1Handler();
  139. }];
  140. [alertController addAction:cancelAction];
  141. }
  142. if (buttonTitle2) {
  143. UIAlertAction *okAction = [UIAlertAction actionWithTitle:buttonTitle2
  144. style:UIAlertActionStyleDefault
  145. handler:^(UIAlertAction * _Nonnull action) {
  146. if (buttonTitle2Handler) buttonTitle2Handler();
  147. }];
  148. [alertController addAction:okAction];
  149. }
  150. [vc presentViewController:alertController animated:YES completion:nil];
  151. return alertController;
  152. }
  153. #define HXAlbumCameraRoll @"HXAlbumCameraRoll"
  154. #define HXAlbumPanoramas @"HXAlbumPanoramas"
  155. #define HXAlbumVideos @"HXAlbumVideos"
  156. #define HXAlbumFavorites @"HXAlbumFavorites"
  157. #define HXAlbumTimelapses @"HXAlbumTimelapses"
  158. #define HXAlbumRecentlyAdded @"HXAlbumRecentlyAdded"
  159. #define HXAlbumRecents @"HXAlbumRecents"
  160. #define HXAlbumBursts @"HXAlbumBursts"
  161. #define HXAlbumSlomoVideos @"HXAlbumSlomoVideos"
  162. #define HXAlbumSelfPortraits @"HXAlbumSelfPortraits"
  163. #define HXAlbumScreenshots @"HXAlbumScreenshots"
  164. #define HXAlbumDepthEffect @"HXAlbumDepthEffect"
  165. #define HXAlbumLivePhotos @"HXAlbumLivePhotos"
  166. #define HXAlbumAnimated @"HXAlbumAnimated"
  167. #endif /* HXPhotoDefine_h */