ZLDefine.h
9.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//
// ZLDefine.h
// 多选相册照片
//
// Created by long on 15/11/26.
// Copyright © 2015年 long. All rights reserved.
//
#ifndef ZLDefine_h
#define ZLDefine_h
#import "ZLProgressHUD.h"
#import "NSBundle+ZLPhotoBrowser.h"
#define ZLPhotoBrowserCameraText @"ZLPhotoBrowserCameraText"
#define ZLPhotoBrowserCameraRecordText @"ZLPhotoBrowserCameraRecordText"
#define ZLPhotoBrowserAblumText @"ZLPhotoBrowserAblumText"
#define ZLPhotoBrowserCancelText @"ZLPhotoBrowserCancelText"
#define ZLPhotoBrowserOriginalText @"ZLPhotoBrowserOriginalText"
#define ZLPhotoBrowserDoneText @"ZLPhotoBrowserDoneText"
#define ZLPhotoBrowserOKText @"ZLPhotoBrowserOKText"
#define ZLPhotoBrowserBackText @"ZLPhotoBrowserBackText"
#define ZLPhotoBrowserPhotoText @"ZLPhotoBrowserPhotoText"
#define ZLPhotoBrowserPreviewText @"ZLPhotoBrowserPreviewText"
#define ZLPhotoBrowserLoadingText @"ZLPhotoBrowserLoadingText"
#define ZLPhotoBrowserHandleText @"ZLPhotoBrowserHandleText"
#define ZLPhotoBrowserSaveImageErrorText @"ZLPhotoBrowserSaveImageErrorText"
#define ZLPhotoBrowserMaxSelectCountText @"ZLPhotoBrowserMaxSelectCountText"
#define ZLPhotoBrowserNoCameraAuthorityText @"ZLPhotoBrowserNoCameraAuthorityText"
#define ZLPhotoBrowserNoAblumAuthorityText @"ZLPhotoBrowserNoAblumAuthorityText"
#define ZLPhotoBrowserNoMicrophoneAuthorityText @"ZLPhotoBrowserNoMicrophoneAuthorityText"
#define ZLPhotoBrowseriCloudPhotoText @"ZLPhotoBrowseriCloudPhotoText"
#define ZLPhotoBrowserGifPreviewText @"ZLPhotoBrowserGifPreviewText"
#define ZLPhotoBrowserVideoPreviewText @"ZLPhotoBrowserVideoPreviewText"
#define ZLPhotoBrowserLivePhotoPreviewText @"ZLPhotoBrowserLivePhotoPreviewText"
#define ZLPhotoBrowserNoPhotoText @"ZLPhotoBrowserNoPhotoText"
#define ZLPhotoBrowserCannotSelectVideo @"ZLPhotoBrowserCannotSelectVideo"
#define ZLPhotoBrowserCannotSelectGIF @"ZLPhotoBrowserCannotSelectGIF"
#define ZLPhotoBrowserCannotSelectLivePhoto @"ZLPhotoBrowserCannotSelectLivePhoto"
#define ZLPhotoBrowseriCloudVideoText @"ZLPhotoBrowseriCloudVideoText"
#define ZLPhotoBrowserEditText @"ZLPhotoBrowserEditText"
#define ZLPhotoBrowserSaveText @"ZLPhotoBrowserSaveText"
#define ZLPhotoBrowserMaxVideoDurationText @"ZLPhotoBrowserMaxVideoDurationText"
#define ZLPhotoBrowserLoadNetImageFailed @"ZLPhotoBrowserLoadNetImageFailed"
#define ZLPhotoBrowserSaveVideoFailed @"ZLPhotoBrowserSaveVideoFailed"
#define ZLPhotoBrowserCameraRoll @"ZLPhotoBrowserCameraRoll"
#define ZLPhotoBrowserPanoramas @"ZLPhotoBrowserPanoramas"
#define ZLPhotoBrowserVideos @"ZLPhotoBrowserVideos"
#define ZLPhotoBrowserFavorites @"ZLPhotoBrowserFavorites"
#define ZLPhotoBrowserTimelapses @"ZLPhotoBrowserTimelapses"
#define ZLPhotoBrowserRecentlyAdded @"ZLPhotoBrowserRecentlyAdded"
#define ZLPhotoBrowserBursts @"ZLPhotoBrowserBursts"
#define ZLPhotoBrowserSlomoVideos @"ZLPhotoBrowserSlomoVideos"
#define ZLPhotoBrowserSelfPortraits @"ZLPhotoBrowserSelfPortraits"
#define ZLPhotoBrowserScreenshots @"ZLPhotoBrowserScreenshots"
#define ZLPhotoBrowserDepthEffect @"ZLPhotoBrowserDepthEffect"
#define ZLPhotoBrowserLivePhotos @"ZLPhotoBrowserLivePhotos"
#define ZLPhotoBrowserAnimated @"ZLPhotoBrowserAnimated"
#define kRGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define zl_weakify(var) __weak typeof(var) weakSelf = var
#define zl_strongify(var) __strong typeof(var) strongSelf = var
#define ZL_IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define ZL_IS_IPHONE_X (ZL_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 812.0f)
#define ZL_SafeAreaBottom (ZL_IS_IPHONE_X ? 34 : 0)
#define kZLPhotoBrowserBundle [NSBundle bundleForClass:[self class]]
// 图片路径
#define kZLPhotoBrowserSrcName(file) [@"ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]
#define kZLPhotoBrowserFrameworkSrcName(file) [@"Frameworks/ZLPhotoBrowser.framework/ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]
#define kViewWidth [[UIScreen mainScreen] bounds].size.width
#define kViewHeight [[UIScreen mainScreen] bounds].size.height
//app名字
#define kInfoDict [NSBundle mainBundle].localizedInfoDictionary ?: [NSBundle mainBundle].infoDictionary
#define kAPPName [kInfoDict valueForKey:@"CFBundleDisplayName"] ?: [kInfoDict valueForKey:@"CFBundleName"]
//自定义图片名称存于plist中的key
#define ZLCustomImageNames @"ZLCustomImageNames"
//设置框架语言的key
#define ZLLanguageTypeKey @"ZLLanguageTypeKey"
//自定义多语言key value存于plist中的key
#define ZLCustomLanguageKeyValue @"ZLCustomLanguageKeyValue"
////////ZLShowBigImgViewController
#define kItemMargin 40
///////ZLBigImageCell 不建议设置太大,太大的话会导致图片加载过慢
#define kMaxImageWidth 500
#define ClippingRatioValue1 @"value1"
#define ClippingRatioValue2 @"value2"
#define ClippingRatioTitleFormat @"titleFormat"
typedef NS_ENUM(NSUInteger, ZLLanguageType) {
//跟随系统语言,默认
ZLLanguageSystem,
//中文简体
ZLLanguageChineseSimplified,
//中文繁体
ZLLanguageChineseTraditional,
//英文
ZLLanguageEnglish,
//日文
ZLLanguageJapanese,
};
//录制视频及拍照分辨率
typedef NS_ENUM(NSUInteger, ZLCaptureSessionPreset) {
ZLCaptureSessionPreset325x288,
ZLCaptureSessionPreset640x480,
ZLCaptureSessionPreset1280x720,
ZLCaptureSessionPreset1920x1080,
ZLCaptureSessionPreset3840x2160,
};
//导出视频类型
typedef NS_ENUM(NSUInteger, ZLExportVideoType) {
//default
ZLExportVideoTypeMov,
ZLExportVideoTypeMp4,
};
//导出视频水印位置
typedef NS_ENUM(NSUInteger, ZLWatermarkLocation) {
ZLWatermarkLocationTopLeft,
ZLWatermarkLocationTopRight,
ZLWatermarkLocationCenter,
ZLWatermarkLocationBottomLeft,
ZLWatermarkLocationBottomRight,
};
static inline void SetViewWidth(UIView *view, CGFloat width) {
CGRect frame = view.frame;
frame.size.width = width;
view.frame = frame;
}
static inline CGFloat GetViewWidth(UIView *view) {
return view.frame.size.width;
}
static inline void SetViewHeight(UIView *view, CGFloat height) {
CGRect frame = view.frame;
frame.size.height = height;
view.frame = frame;
}
static inline CGFloat GetViewHeight(UIView *view) {
return view.frame.size.height;
}
static inline NSString * GetLocalLanguageTextValue (NSString *key) {
NSDictionary *dic = [[NSUserDefaults standardUserDefaults] valueForKey:ZLCustomLanguageKeyValue];
if ([dic.allKeys containsObject:key]) {
return dic[key];
}
return [NSBundle zlLocalizedStringForKey:key];
}
static inline UIImage * GetImageWithName(NSString *name) {
NSArray *names = [[NSUserDefaults standardUserDefaults] valueForKey:ZLCustomImageNames];
if ([names containsObject:name]) {
return [UIImage imageNamed:name];
}
return [UIImage imageNamed:kZLPhotoBrowserSrcName(name)]?:[UIImage imageNamed:kZLPhotoBrowserFrameworkSrcName(name)];
}
static inline CGFloat GetMatchValue(NSString *text, CGFloat fontSize, BOOL isHeightFixed, CGFloat fixedValue) {
CGSize size;
if (isHeightFixed) {
size = CGSizeMake(MAXFLOAT, fixedValue);
} else {
size = CGSizeMake(fixedValue, MAXFLOAT);
}
CGSize resultSize;
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0) {
//返回计算出的size
resultSize = [text boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:fontSize]} context:nil].size;
}
if (isHeightFixed) {
return resultSize.width;
} else {
return resultSize.height;
}
}
static inline void ShowAlert(NSString *message, UIViewController *sender) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:GetLocalLanguageTextValue(ZLPhotoBrowserOKText) style:UIAlertActionStyleDefault handler:nil];
[alert addAction:action];
[sender presentViewController:alert animated:YES completion:nil];
}
static inline CABasicAnimation * GetPositionAnimation(id fromValue, id toValue, CFTimeInterval duration, NSString *keyPath) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:keyPath];
animation.fromValue = fromValue;
animation.toValue = toValue;
animation.duration = duration;
animation.repeatCount = 0;
animation.autoreverses = NO;
//以下两个设置,保证了动画结束后,layer不会回到初始位置
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
return animation;
}
static inline CAKeyframeAnimation * GetBtnStatusChangedAnimation() {
CAKeyframeAnimation *animate = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animate.duration = 0.3;
animate.removedOnCompletion = YES;
animate.fillMode = kCAFillModeForwards;
animate.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.7, 0.7, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
return animate;
}
static inline NSInteger GetDuration (NSString *duration) {
NSArray *arr = [duration componentsSeparatedByString:@":"];
NSInteger d = 0;
for (int i = 0; i < arr.count; i++) {
d += [arr[i] integerValue] * pow(60, (arr.count-1-i));
}
return d;
}
static inline NSDictionary *
GetCustomClipRatio() {
return @{ClippingRatioValue1: @(0), ClippingRatioValue2: @(0), ClippingRatioTitleFormat: @"Custom"};
}
static inline NSDictionary * GetClipRatio(NSInteger value1, NSInteger value2) {
return @{ClippingRatioValue1: @(value1), ClippingRatioValue2: @(value2), ClippingRatioTitleFormat: @"%g : %g"};
}
#endif /* ZLDefine_h */