This commit is contained in:
2025-12-15 16:41:53 +08:00
parent 06dee39566
commit a7574cd286
5 changed files with 153 additions and 82 deletions

View File

@@ -25,13 +25,12 @@ static __weak UIView *sContainerView = nil; // 缺省承载视图(
if (NSThread.isMainThread) { blk(); } else { dispatch_async(dispatch_get_main_queue(), blk); }
}
+ (MBProgressHUD *)ensureHUDWithMask:(KBHUDMaskType)mask tap:(BOOL)tap {
// 使
/// HUD 宿
+ (UIView *)kb_resolvedHostView {
UIView *hostView = sContainerView;
#ifndef KB_APP_EXTENSION
// App 退 KeyWindow
if (!hostView) {
// KB_KeyWindow App PrefixHeader
UIWindow *win = nil;
// 访 UIApplication App Extension
Class uiAppClass = NSClassFromString(@"UIApplication");
@@ -51,7 +50,11 @@ static __weak UIView *sContainerView = nil; // 缺省承载视图(
hostView = win;
}
#endif
return hostView;
}
+ (MBProgressHUD *)ensureHUDWithMask:(KBHUDMaskType)mask tap:(BOOL)tap {
UIView *hostView = [self kb_resolvedHostView];
if (!hostView) { return nil; }
MBProgressHUD *hud = sHUD;
@@ -119,8 +122,27 @@ static __weak UIView *sContainerView = nil; // 缺省承载视图(
+ (void)_showText:(NSString *)text icon:(nullable UIImage *)icon {
[self onMain:^{
MBProgressHUD *hud = [self ensureHUDWithMask:sMaskType tap:sDefaultTapToDismiss];
if (!hud) { return; }
MBProgressHUD *loadingHUD = sHUD;
if (loadingHUD) {
[loadingHUD hideAnimated:YES];
}
sHUD = nil;
UIView *hostView = [self kb_resolvedHostView];
if (!hostView) { return; }
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:hostView animated:YES];
hud.removeFromSuperViewOnHide = YES;
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.layer.cornerRadius = 12.0;
hud.bezelView.color = [UIColor colorWithWhite:0 alpha:0.8];
hud.contentColor = UIColor.whiteColor;
hud.margin = 16;
hud.label.numberOfLines = 0;
hud.detailsLabel.numberOfLines = 0;
[self applyMaskType:sMaskType hud:hud];
[self applyTapToDismiss:sDefaultTapToDismiss hud:hud];
hud.mode = icon ? MBProgressHUDModeCustomView : MBProgressHUDModeText;
hud.label.text = text ?: @"";
hud.detailsLabel.text = nil;