/
JGProgressHUD.h
executable file
·313 lines (232 loc) · 9.67 KB
/
JGProgressHUD.h
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//
// JGProgressHUD.h
// JGProgressHUD
//
// Created by Jonas Gessner on 20.7.14.
// Copyright (c) 2014 Jonas Gessner. All rights reserved.
//
#import "JGProgressHUD-Defines.h"
#import "JGProgressHUDAnimation.h"
#import "JGProgressHUDFadeAnimation.h"
#import "JGProgressHUDFadeZoomAnimation.h"
#import "JGProgressHUDIndicatorView.h"
#import "JGProgressHUDErrorIndicatorView.h"
#import "JGProgressHUDSuccessIndicatorView.h"
#import "JGProgressHUDRingIndicatorView.h"
#import "JGProgressHUDPieIndicatorView.h"
#import "JGProgressHUDIndeterminateIndicatorView.h"
@class JGProgressHUD;
@protocol JGProgressHUDDelegate <NSObject>
@optional
/**
Called before the HUD will appear.
@param view The view in which the HUD is presented.
*/
- (void)progressHUD:(JGProgressHUD *)progressHUD willPresentInView:(UIView *)view;
/**
Called after the HUD appeared.
@param view The view in which the HUD is presented.
*/
- (void)progressHUD:(JGProgressHUD *)progressHUD didPresentInView:(UIView *)view;
/**
Called before the HUD will disappear.
@param view The view in which the HUD is presented and will be dismissed from.
*/
- (void)progressHUD:(JGProgressHUD *)progressHUD willDismissFromView:(UIView *)view;
/**
Called after the HUD has disappeared.
@param view The view in which the HUD was presented and was be dismissed from.
*/
- (void)progressHUD:(JGProgressHUD *)progressHUD didDismissFromView:(UIView *)view;
@end
/**
A HUD to indicate progress, success, error, warnings or other notifications to the user.
@note Remember to call every method from the main thread! UIKit => main thread!
@attention This applies only to iOS 8 and higher: You may not add JGProgressHUD to a view which has an alpha value < 1.0 or to a view which is a subview of a view with an alpha value < 1.0.
*/
@interface JGProgressHUD : UIView
/**
Designated initializer.
@param style The appearance style of the HUD.
*/
- (instancetype)initWithStyle:(JGProgressHUDStyle)style;
/**
Convenience initializer.
@param style The appearance style of the HUD.
*/
+ (instancetype)progressHUDWithStyle:(JGProgressHUDStyle)style;
/**
The view in which the HUD is presented.
*/
@property (nonatomic, weak, readonly) UIView *targetView;
/**
The delegate of the HUD.
@sa JGProgressHUDDelegate.
*/
@property (nonatomic, weak) id <JGProgressHUDDelegate> delegate;
/**
A block to be invoked when the HUD view is tapped.
@note The interaction type of the HUD must be @c JGProgressHUDInteractionTypeBlockTouchesOnHUDView or @c JGProgressHUDInteractionTypeBlockAllTouches, otherwise this block won't be fired.
*/
@property (nonatomic, copy) void (^tapOnHUDViewBlock)(JGProgressHUD *HUD);
/**
A block to be invoked when the area outside of the HUD view is tapped.
@note The interaction type of the HUD must be @c JGProgressHUDInteractionTypeBlockAllTouches, otherwise this block won't be fired.
*/
@property (nonatomic, copy) void (^tapOutsideBlock)(JGProgressHUD *HUD);
/**
The actual HUD view visible on screen. You may add animations or shadows to this view.
*/
@property (nonatomic, strong, readonly) UIView *HUDView;
/**
The content view inside the @c HUDView. If you want to add additional views to the HUD you should add them as subview to the @c contentView.
*/
@property (nonatomic, strong, readonly) UIView *contentView;
/**
The label used to present text on the HUD. Set the @c text property of this label to change the displayed text. You may not change the label's @c frame or @c bounds.
*/
@property (nonatomic, strong, readonly) UILabel *textLabel;
/**
The label used to present detail text on the HUD. Set the @c text property of this label to change the displayed text. You may not change the label's @c frame or @c bounds.
*/
@property (nonatomic, strong, readonly) UILabel *detailTextLabel;
/**
The indicator view. You can assign a custom subclass of JGProgressHUDIndicatorView to this property or one of the default indicator views (if you do so, you should assign it before showing the HUD).
@b Default: JGProgressHUDIndeterminateIndicatorView.
*/
@property (nonatomic, strong) JGProgressHUDIndicatorView *indicatorView;
/**
Interaction type of the HUD. Determines whether touches should be let through to the views behind the HUD.
@sa JGProgressHUDInteractionType.
@b Default: JGProgressHUDInteractionTypeBlockAllTouches.
*/
@property (nonatomic, assign) JGProgressHUDInteractionType interactionType;
/**
Parallax mode for the HUD. This setting determines whether the HUD should have a parallax (@c UIDeviceMotion) effect.
@sa JGProgressHUDParallaxMode.
@b Default: JGProgressHUDParallaxModeDevice.
*/
@property (nonatomic, assign) JGProgressHUDParallaxMode parallaxMode;
/**
The appearance style of the HUD.
@b Default: JGProgressHUDStyleExtraLight.
*/
@property (nonatomic, assign, readonly) JGProgressHUDStyle style;
/**
If the HUD should always have the same width and height.
@b Default: NO.
*/
@property (nonatomic, assign) BOOL square;
/**
The radius used for rounding the four corners of the HUD view.
@b Default: 10.0.
*/
@property (nonatomic, assign) CGFloat cornerRadius;
/**
Insets the contents of the HUD.
@b Default: (20, 20, 20, 20).
*/
@property (nonatomic, assign) UIEdgeInsets contentInsets;
/**
Insets the HUD from the frame of the hosting view or from the specified frame to present the HUD from.
@b Default: (20, 20, 20, 20).
*/
@property (nonatomic, assign) UIEdgeInsets marginInsets;
/**
The position of the HUD inside the hosting view's frame, or inside the specified frame.
@b Default: JGProgressHUDPositionCenter
*/
@property (nonatomic, assign) JGProgressHUDPosition position;
/**
The animation used for showing and dismissing the HUD.
@b Default: JGProgressHUDFadeAnimation.
*/
@property (nonatomic, strong) JGProgressHUDAnimation *animation;
/**
The animation duration for a layout change (ex. Changing the @c text, the @c position, the @c progressIndicatorView or the @c useProgressIndicatorView property).
@b Default: 0.3.
*/
@property (nonatomic, assign) NSTimeInterval layoutChangeAnimationDuration;
/**
@return Whether the HUD is visible on screen.
*/
@property (nonatomic, assign, readonly, getter = isVisible) BOOL visible;
/**
The progress to display using the @c progressIndicatorView. A change of this property is not animated. Use the @c setProgress:animated: method for an animated progress change.
@b Default: 0.0.
*/
@property (nonatomic, assign) float progress;
/**
Adjusts the current progress shown by the receiver, optionally animating the change.
The current progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the completion of the task. The default value is 0.0. Values less than 0.0 and greater than 1.0 are pinned to those limits.
@param progress The new progress value.
@param animated YES if the change should be animated, NO if the change should happen immediately.
*/
- (void)setProgress:(float)progress animated:(BOOL)animated;
/**
Specifies a minimum time that the HUD will be on-screen. Useful to prevent the HUD from flashing quickly on the screen when indeterminate tasks complete more quickly than expected.
@b Default: 0.0.
*/
@property (nonatomic, assign) NSTimeInterval minimumDisplayTime;
/**
Determines whether Voice Over announcements should be made upon displaying the HUD (if Voice Over is active).
@b Default: YES
*/
@property (nonatomic, assign) BOOL voiceOverEnabled;
/**
Shows the HUD animated. You should preferably show the HUD in a UIViewController's view. The HUD will be repositioned in response to rotation and keyboard show/hide notifications.
@param view The view to show the HUD in. The frame of the @c view will be used to calculate the position of the HUD.
*/
- (void)showInView:(UIView *)view;
/**
Shows the HUD. You should preferably show the HUD in a UIViewController's view. The HUD will be repositioned in response to rotation and keyboard show/hide notifications.
@param view The view to show the HUD in. The frame of the @c view will be used to calculate the position of the HUD.
@param animated If the HUD should show with an animation.
*/
- (void)showInView:(UIView *)view animated:(BOOL)animated;
/**
Shows the HUD animated. You should preferably show the HUD in a UIViewController's view.
@param view The view to show the HUD in.
@param rect The rect allocated in @c view for displaying the HUD.
*/
- (void)showInRect:(CGRect)rect inView:(UIView *)view;
/**
Shows the HUD. You should preferably show the HUD in a UIViewController's view.
@param view The view to show the HUD in.
@param rect The rect allocated in @c view for displaying the HUD.
@param animated If the HUD should show with an animation.
*/
- (void)showInRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;
/**
Dismisses the HUD animated.
*/
- (void)dismiss;
/**
Dismisses the HUD.
@param animated If the HUD should dismiss with an animation.
*/
- (void)dismissAnimated:(BOOL)animated;
/**
Dismisses the HUD animated after a delay.
@param delay The delay until the HUD will be dismissed.
*/
- (void)dismissAfterDelay:(NSTimeInterval)delay;
/**
Dismisses the HUD after a delay.
@param delay The delay until the HUD will be dismissed.
@param animated If the HUD should dismiss with an animation.
*/
- (void)dismissAfterDelay:(NSTimeInterval)delay animated:(BOOL)animated;
@end
@interface JGProgressHUD (HUDManagement)
/**
@param view The view to return all visible progress HUDs for.
@return All visible progress HUDs in the view.
*/
+ (NSArray *)allProgressHUDsInView:(UIView *)view;
/**
@param view The view to return all visible progress HUDs for.
@return All visible progress HUDs in the view and its subviews.
*/
+ (NSArray *)allProgressHUDsInViewHierarchy:(UIView *)view;
@end