Download GIFs with Antenna Browser for Reddit natively
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MBProgressHUD.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. //
  2. // MBProgressHUD.h
  3. // Version 1.0.0
  4. // Created by Matej Bukovinski on 2.4.09.
  5. //
  6. // This code is distributed under the terms and conditions of the MIT license.
  7. // Copyright © 2009-2016 Matej Bukovinski
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. #import <Foundation/Foundation.h>
  27. #import <UIKit/UIKit.h>
  28. #import <CoreGraphics/CoreGraphics.h>
  29. NS_ASSUME_NONNULL_BEGIN
  30. @class MBBackgroundView;
  31. @protocol MBProgressHUDDelegate;
  32. extern CGFloat const MBProgressMaxOffset;
  33. typedef NS_ENUM(NSInteger, MBProgressHUDMode) {
  34. /// UIActivityIndicatorView.
  35. MBProgressHUDModeIndeterminate,
  36. /// A round, pie-chart like, progress view.
  37. MBProgressHUDModeDeterminate,
  38. /// Horizontal progress bar.
  39. MBProgressHUDModeDeterminateHorizontalBar,
  40. /// Ring-shaped progress view.
  41. MBProgressHUDModeAnnularDeterminate,
  42. /// Shows a custom view.
  43. MBProgressHUDModeCustomView,
  44. /// Shows only labels.
  45. MBProgressHUDModeText
  46. };
  47. typedef NS_ENUM(NSInteger, MBProgressHUDAnimation) {
  48. /// Opacity animation
  49. MBProgressHUDAnimationFade,
  50. /// Opacity + scale animation (zoom in when appearing zoom out when disappearing)
  51. MBProgressHUDAnimationZoom,
  52. /// Opacity + scale animation (zoom out style)
  53. MBProgressHUDAnimationZoomOut,
  54. /// Opacity + scale animation (zoom in style)
  55. MBProgressHUDAnimationZoomIn
  56. };
  57. typedef NS_ENUM(NSInteger, MBProgressHUDBackgroundStyle) {
  58. /// Solid color background
  59. MBProgressHUDBackgroundStyleSolidColor,
  60. /// UIVisualEffectView or UIToolbar.layer background view
  61. MBProgressHUDBackgroundStyleBlur
  62. };
  63. typedef void (^MBProgressHUDCompletionBlock)();
  64. /**
  65. * Displays a simple HUD window containing a progress indicator and two optional labels for short messages.
  66. *
  67. * This is a simple drop-in class for displaying a progress HUD view similar to Apple's private UIProgressHUD class.
  68. * The MBProgressHUD window spans over the entire space given to it by the initWithFrame: constructor and catches all
  69. * user input on this region, thereby preventing the user operations on components below the view.
  70. *
  71. * @note To still allow touches to pass through the HUD, you can set hud.userInteractionEnabled = NO.
  72. * @attention MBProgressHUD is a UI class and should therefore only be accessed on the main thread.
  73. */
  74. @interface MBProgressHUD : UIView
  75. /**
  76. * Creates a new HUD, adds it to provided view and shows it. The counterpart to this method is hideHUDForView:animated:.
  77. *
  78. * @note This method sets removeFromSuperViewOnHide. The HUD will automatically be removed from the view hierarchy when hidden.
  79. *
  80. * @param view The view that the HUD will be added to
  81. * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use
  82. * animations while appearing.
  83. * @return A reference to the created HUD.
  84. *
  85. * @see hideHUDForView:animated:
  86. * @see animationType
  87. */
  88. + (instancetype)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
  89. /// @name Showing and hiding
  90. /**
  91. * Finds the top-most HUD subview and hides it. The counterpart to this method is showHUDAddedTo:animated:.
  92. *
  93. * @note This method sets removeFromSuperViewOnHide. The HUD will automatically be removed from the view hierarchy when hidden.
  94. *
  95. * @param view The view that is going to be searched for a HUD subview.
  96. * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
  97. * animations while disappearing.
  98. * @return YES if a HUD was found and removed, NO otherwise.
  99. *
  100. * @see showHUDAddedTo:animated:
  101. * @see animationType
  102. */
  103. + (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;
  104. /**
  105. * Finds the top-most HUD subview and returns it.
  106. *
  107. * @param view The view that is going to be searched.
  108. * @return A reference to the last HUD subview discovered.
  109. */
  110. + (nullable MBProgressHUD *)HUDForView:(UIView *)view;
  111. /**
  112. * A convenience constructor that initializes the HUD with the view's bounds. Calls the designated constructor with
  113. * view.bounds as the parameter.
  114. *
  115. * @param view The view instance that will provide the bounds for the HUD. Should be the same instance as
  116. * the HUD's superview (i.e., the view that the HUD will be added to).
  117. */
  118. - (instancetype)initWithView:(UIView *)view;
  119. /**
  120. * Displays the HUD.
  121. *
  122. * @note You need to make sure that the main thread completes its run loop soon after this method call so that
  123. * the user interface can be updated. Call this method when your task is already set up to be executed in a new thread
  124. * (e.g., when using something like NSOperation or making an asynchronous call like NSURLRequest).
  125. *
  126. * @param animated If set to YES the HUD will appear using the current animationType. If set to NO the HUD will not use
  127. * animations while appearing.
  128. *
  129. * @see animationType
  130. */
  131. - (void)showAnimated:(BOOL)animated;
  132. /**
  133. * Hides the HUD. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to
  134. * hide the HUD when your task completes.
  135. *
  136. * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
  137. * animations while disappearing.
  138. *
  139. * @see animationType
  140. */
  141. - (void)hideAnimated:(BOOL)animated;
  142. /**
  143. * Hides the HUD after a delay. This still calls the hudWasHidden: delegate. This is the counterpart of the show: method. Use it to
  144. * hide the HUD when your task completes.
  145. *
  146. * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
  147. * animations while disappearing.
  148. * @param delay Delay in seconds until the HUD is hidden.
  149. *
  150. * @see animationType
  151. */
  152. - (void)hideAnimated:(BOOL)animated afterDelay:(NSTimeInterval)delay;
  153. /**
  154. * The HUD delegate object. Receives HUD state notifications.
  155. */
  156. @property (weak, nonatomic, nullable) id<MBProgressHUDDelegate> delegate;
  157. /**
  158. * Called after the HUD is hiden.
  159. */
  160. @property (copy, nullable) MBProgressHUDCompletionBlock completionBlock;
  161. /*
  162. * Grace period is the time (in seconds) that the invoked method may be run without
  163. * showing the HUD. If the task finishes before the grace time runs out, the HUD will
  164. * not be shown at all.
  165. * This may be used to prevent HUD display for very short tasks.
  166. * Defaults to 0 (no grace time).
  167. */
  168. @property (assign, nonatomic) NSTimeInterval graceTime;
  169. /**
  170. * The minimum time (in seconds) that the HUD is shown.
  171. * This avoids the problem of the HUD being shown and than instantly hidden.
  172. * Defaults to 0 (no minimum show time).
  173. */
  174. @property (assign, nonatomic) NSTimeInterval minShowTime;
  175. /**
  176. * Removes the HUD from its parent view when hidden.
  177. * Defaults to NO.
  178. */
  179. @property (assign, nonatomic) BOOL removeFromSuperViewOnHide;
  180. /// @name Appearance
  181. /**
  182. * MBProgressHUD operation mode. The default is MBProgressHUDModeIndeterminate.
  183. */
  184. @property (assign, nonatomic) MBProgressHUDMode mode;
  185. /**
  186. * A color that gets forwarded to all labels and supported indicators. Also sets the tintColor
  187. * for custom views on iOS 7+. Set to nil to manage color individually.
  188. * Defaults to semi-translucent black on iOS 7 and later and white on earlier iOS versions.
  189. */
  190. @property (strong, nonatomic, nullable) UIColor *contentColor UI_APPEARANCE_SELECTOR;
  191. /**
  192. * The animation type that should be used when the HUD is shown and hidden.
  193. */
  194. @property (assign, nonatomic) MBProgressHUDAnimation animationType UI_APPEARANCE_SELECTOR;
  195. /**
  196. * The bezel offset relative to the center of the view. You can use MBProgressMaxOffset
  197. * and -MBProgressMaxOffset to move the HUD all the way to the screen edge in each direction.
  198. * E.g., CGPointMake(0.f, MBProgressMaxOffset) would position the HUD centered on the bottom edge.
  199. */
  200. @property (assign, nonatomic) CGPoint offset UI_APPEARANCE_SELECTOR;
  201. /**
  202. * The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views).
  203. * This also represents the minimum bezel distance to the edge of the HUD view.
  204. * Defaults to 20.f
  205. */
  206. @property (assign, nonatomic) CGFloat margin UI_APPEARANCE_SELECTOR;
  207. /**
  208. * The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size).
  209. */
  210. @property (assign, nonatomic) CGSize minSize UI_APPEARANCE_SELECTOR;
  211. /**
  212. * Force the HUD dimensions to be equal if possible.
  213. */
  214. @property (assign, nonatomic, getter = isSquare) BOOL square UI_APPEARANCE_SELECTOR;
  215. /**
  216. * When enabled, the bezel center gets slightly affected by the device accelerometer data.
  217. * Has no effect on iOS < 7.0. Defaults to YES.
  218. */
  219. @property (assign, nonatomic, getter=areDefaultMotionEffectsEnabled) BOOL defaultMotionEffectsEnabled UI_APPEARANCE_SELECTOR;
  220. /// @name Progress
  221. /**
  222. * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0.
  223. */
  224. @property (assign, nonatomic) float progress;
  225. /// @name ProgressObject
  226. /**
  227. * The NSProgress object feeding the progress information to the progress indicator.
  228. */
  229. @property (strong, nonatomic, nullable) NSProgress *progressObject;
  230. /// @name Views
  231. /**
  232. * The view containing the labels and indicator (or customView).
  233. */
  234. @property (strong, nonatomic, readonly) MBBackgroundView *bezelView;
  235. /**
  236. * View covering the entire HUD area, placed behind bezelView.
  237. */
  238. @property (strong, nonatomic, readonly) MBBackgroundView *backgroundView;
  239. /**
  240. * The UIView (e.g., a UIImageView) to be shown when the HUD is in MBProgressHUDModeCustomView.
  241. * The view should implement intrinsicContentSize for proper sizing. For best results use approximately 37 by 37 pixels.
  242. */
  243. @property (strong, nonatomic, nullable) UIView *customView;
  244. /**
  245. * A label that holds an optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit
  246. * the entire text.
  247. */
  248. @property (strong, nonatomic, readonly) UILabel *label;
  249. /**
  250. * A label that holds an optional details message displayed below the labelText message. The details text can span multiple lines.
  251. */
  252. @property (strong, nonatomic, readonly) UILabel *detailsLabel;
  253. /**
  254. * A button that is placed below the labels. Visible only if a target / action is added.
  255. */
  256. @property (strong, nonatomic, readonly) UIButton *button;
  257. @end
  258. @protocol MBProgressHUDDelegate <NSObject>
  259. @optional
  260. /**
  261. * Called after the HUD was fully hidden from the screen.
  262. */
  263. - (void)hudWasHidden:(MBProgressHUD *)hud;
  264. @end
  265. /**
  266. * A progress view for showing definite progress by filling up a circle (pie chart).
  267. */
  268. @interface MBRoundProgressView : UIView
  269. /**
  270. * Progress (0.0 to 1.0)
  271. */
  272. @property (nonatomic, assign) float progress;
  273. /**
  274. * Indicator progress color.
  275. * Defaults to white [UIColor whiteColor].
  276. */
  277. @property (nonatomic, strong) UIColor *progressTintColor;
  278. /**
  279. * Indicator background (non-progress) color.
  280. * Only applicable on iOS versions older than iOS 7.
  281. * Defaults to translucent white (alpha 0.1).
  282. */
  283. @property (nonatomic, strong) UIColor *backgroundTintColor;
  284. /*
  285. * Display mode - NO = round or YES = annular. Defaults to round.
  286. */
  287. @property (nonatomic, assign, getter = isAnnular) BOOL annular;
  288. @end
  289. /**
  290. * A flat bar progress view.
  291. */
  292. @interface MBBarProgressView : UIView
  293. /**
  294. * Progress (0.0 to 1.0)
  295. */
  296. @property (nonatomic, assign) float progress;
  297. /**
  298. * Bar border line color.
  299. * Defaults to white [UIColor whiteColor].
  300. */
  301. @property (nonatomic, strong) UIColor *lineColor;
  302. /**
  303. * Bar background color.
  304. * Defaults to clear [UIColor clearColor];
  305. */
  306. @property (nonatomic, strong) UIColor *progressRemainingColor;
  307. /**
  308. * Bar progress color.
  309. * Defaults to white [UIColor whiteColor].
  310. */
  311. @property (nonatomic, strong) UIColor *progressColor;
  312. @end
  313. @interface MBBackgroundView : UIView
  314. /**
  315. * The background style.
  316. * Defaults to MBProgressHUDBackgroundStyleBlur on iOS 7 or later and MBProgressHUDBackgroundStyleSolidColor otherwise.
  317. * @note Due to iOS 7 not supporting UIVisualEffectView, the blur effect differs slightly between iOS 7 and later versions.
  318. */
  319. @property (nonatomic) MBProgressHUDBackgroundStyle style;
  320. /**
  321. * The background color or the blur tint color.
  322. * @note Due to iOS 7 not supporting UIVisualEffectView, the blur effect differs slightly between iOS 7 and later versions.
  323. */
  324. @property (nonatomic, strong) UIColor *color;
  325. @end
  326. @interface MBProgressHUD (Deprecated)
  327. + (NSArray *)allHUDsForView:(UIView *)view __attribute__((deprecated("Store references when using more than one HUD per view.")));
  328. + (NSUInteger)hideAllHUDsForView:(UIView *)view animated:(BOOL)animated __attribute__((deprecated("Store references when using more than one HUD per view.")));
  329. - (id)initWithWindow:(UIWindow *)window __attribute__((deprecated("Use initWithView: instead.")));
  330. - (void)show:(BOOL)animated __attribute__((deprecated("Use showAnimated: instead.")));
  331. - (void)hide:(BOOL)animated __attribute__((deprecated("Use hideAnimated: instead.")));
  332. - (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay __attribute__((deprecated("Use hideAnimated:afterDelay: instead.")));
  333. - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated __attribute__((deprecated("Use GCD directly.")));
  334. - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block __attribute__((deprecated("Use GCD directly.")));
  335. - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(nullable MBProgressHUDCompletionBlock)completion __attribute__((deprecated("Use GCD directly.")));
  336. - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue __attribute__((deprecated("Use GCD directly.")));
  337. - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue
  338. completionBlock:(nullable MBProgressHUDCompletionBlock)completion __attribute__((deprecated("Use GCD directly.")));
  339. @property (assign) BOOL taskInProgress __attribute__((deprecated("No longer needed.")));
  340. @property (nonatomic, copy) NSString *labelText __attribute__((deprecated("Use label.text instead.")));
  341. @property (nonatomic, strong) UIFont *labelFont __attribute__((deprecated("Use label.font instead.")));
  342. @property (nonatomic, strong) UIColor *labelColor __attribute__((deprecated("Use label.textColor instead.")));
  343. @property (nonatomic, copy) NSString *detailsLabelText __attribute__((deprecated("Use detailsLabel.text instead.")));
  344. @property (nonatomic, strong) UIFont *detailsLabelFont __attribute__((deprecated("Use detailsLabel.font instead.")));
  345. @property (nonatomic, strong) UIColor *detailsLabelColor __attribute__((deprecated("Use detailsLabel.textColor instead.")));
  346. @property (assign, nonatomic) CGFloat opacity __attribute__((deprecated("Customize bezelView properties instead.")));
  347. @property (strong, nonatomic) UIColor *color __attribute__((deprecated("Customize the bezelView color instead.")));
  348. @property (assign, nonatomic) CGFloat xOffset __attribute__((deprecated("Set offset.x instead.")));
  349. @property (assign, nonatomic) CGFloat yOffset __attribute__((deprecated("Set offset.y instead.")));
  350. @property (assign, nonatomic) CGFloat cornerRadius __attribute__((deprecated("Set bezelView.layer.cornerRadius instead.")));
  351. @property (assign, nonatomic) BOOL dimBackground __attribute__((deprecated("Customize HUD background properties instead.")));
  352. @property (strong, nonatomic) UIColor *activityIndicatorColor __attribute__((deprecated("Use UIAppearance to customize UIActivityIndicatorView. E.g.: [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor redColor];")));
  353. @property (atomic, assign, readonly) CGSize size __attribute__((deprecated("Get the bezelView.frame.size instead.")));
  354. @end
  355. NS_ASSUME_NONNULL_END