123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // KSHudLoagingManager.m
- // GuanYueTeam
- //
- // Created by 王智 on 2022/11/14.
- //
- #import "KSHudLoagingManager.h"
- #import <MBProgressHUD/MBProgressHUD.h>
- #import "UIView+Hints.h"
- #define PROMPT_TIME 1.5f
- @interface KSHudLoagingManager ()
- @property (nonatomic, strong) MBProgressHUD *HUD;
- @end
- @implementation KSHudLoagingManager
- + (instancetype)shareInstance {
-
- static KSHudLoagingManager *manager = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- manager = [[KSHudLoagingManager alloc] init];
- });
- return manager;
- }
- - (void)showHUD {
- dispatch_main_async_safe(^{
- [self removeLoadingView];
- UIWindow *window = [[UIApplication sharedApplication ] keyWindow];
- self.HUD = [window addHUDActivityViewToView:nil
- HintsText:@"加载中..."
- Image:nil
- hideAfterDelay:15.0f
- HaveDim:NO];
- self.HUD.mode = MBProgressHUDModeIndeterminate;//显示菊花
-
- [window bringSubviewToFront:self.HUD];
- });
- }
- - (void)removeHUD {
- dispatch_delay_block(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC), ^{
- [self removeLoadingView];
- });
- }
- - (void)removeLoadingView {
- if (self.HUD) {
- [self.HUD removeFromSuperview];
- }
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
- }
- - (void)MBPShow:(NSString *)str inView:(UIView *)displayView {
- [self showHud:str inView:displayView autoHide:YES];
- }
- - (void)showHud:(NSString *)str inView:(UIView *)displayView autoHide:(BOOL)autoHide {
- [self removeLoadingView];
- self.HUD = [MBProgressHUD showHUDAddedTo:displayView animated:YES];
- self.HUD.removeFromSuperViewOnHide =YES;
- self.HUD.mode = MBProgressHUDModeText;
- self.HUD.label.text = str;
- self.HUD.label.numberOfLines = 0;
- self.HUD.minSize = CGSizeMake(132.f, 60.0f);
- self.HUD.label.textColor = [UIColor whiteColor];
- self.HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
- self.HUD.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8f);
- if (autoHide) {
- double hiddenTime = str.length > 15 ? 3.0f : 1.5f;
- [self.HUD hideAnimated:YES afterDelay:hiddenTime];
- }
- }
- - (void)MBShowInWindow:(NSString *)str {
- [self showHud:str inView:[NSObject getKeyWindow] autoHide:NO];
- }
- - (void)MBShowAUTOHidingInWindow:(NSString *)str {
- [self showHud:str inView:[NSObject getKeyWindow] autoHide:YES];
- }
- - (void)KSShowMsg:(NSString *)message promptCompletion:(void (^)(void))promptCompletion {
- [self KSShowMsg:message inView:[NSObject getKeyWindow] promptCompletion:promptCompletion];
-
- }
- - (void)KSShowMsg:(NSString *)message inView:(UIView *)displayView promptCompletion:(void (^)(void))promptCompletion {
- [self removeLoadingView];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:displayView animated:YES];
- hud.removeFromSuperViewOnHide = YES;
- hud.mode = MBProgressHUDModeText;
- hud.label.text = message;
- hud.label.numberOfLines = 0;
- hud.label.textColor = [UIColor whiteColor];
- hud.minSize = CGSizeMake(132.0f, 40.0f);
- hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
- hud.bezelView.backgroundColor = HexRGBAlpha(0x000000, 0.8);
- [hud hideAnimated:YES afterDelay:PROMPT_TIME];
-
- dispatch_delay_block(DISPATCH_TIME_NOW, (int64_t)(PROMPT_TIME * NSEC_PER_SEC), ^{
- promptCompletion();
- });
- }
- @end
|