1
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user