MBProgressHUD 无法覆盖键盘

发布于 2024-12-10 04:35:14 字数 387 浏览 3 评论 0原文

当我尝试在键盘也显示的情况下显示 MBProgressHUD 时,我使用下面的代码,但 HUD 对象无法覆盖键盘:

SNSSharerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
HUD = [[MBProgressHUD showHUDAddedTo:delegate.window animated:YES] retain];
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = @"Posting...";
[HUD show:YES];

我认为 HUD 对象显示在委托窗口前面,键盘也显示,所以添加了最后,即前面。我错了吗?

When I try to show a MBProgressHUD while the keyboard is also showing, I use the code below but the HUD object cannot cover the keyboard:

SNSSharerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
HUD = [[MBProgressHUD showHUDAddedTo:delegate.window animated:YES] retain];
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = @"Posting...";
[HUD show:YES];

I thought the HUD object shows in front of the window of delegate, the keyboard shows too, so which added last, which is front. Am I wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-12-17 04:35:14

将 hud 添加到包含键盘的第二个窗口。
当键盘显示时,应用程序中有两个 UIWindow 实例。第一个是常规窗口,第二个是临时键盘窗口。
代码:

UIWindow *tempKeyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
MBProgressHUD *hud=[[MBProgressHUD alloc] initWithWindow:tempKeyboardWindow];
hub.mode=MBProgressHUDModeIndeterminate;
hub.labelText=@"Sending...";
[tempKeyboardWindow addSubview:hud];
[hud show:YES];

在ios4.3和ios5.x中测试,确实有效。

Add hud to the second window which contains the keyboard.
When keyboard showing, there are two UIWindow instances in application. The first one is the regular window, the second one is the temp keyboard window.
Code:

UIWindow *tempKeyboardWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
MBProgressHUD *hud=[[MBProgressHUD alloc] initWithWindow:tempKeyboardWindow];
hub.mode=MBProgressHUDModeIndeterminate;
hub.labelText=@"Sending...";
[tempKeyboardWindow addSubview:hud];
[hud show:YES];

Tested in ios4.3 and ios5.x, it really works.

不必在意 2024-12-17 04:35:14

对于ios 9,改为 [[[UIApplication sharedApplication] windows] objectAtIndex:1] 尝试使用 [[[UIApplication sharedApplication] windows] lastObject]

所以它会像这样

UIWindow *tempKeyboardWindow = [[[UIApplication sharedApplication] windows] lastObject];
MBProgressHUD *hud=[[MBProgressHUD alloc] initWithWindow:tempKeyboardWindow];
hub.mode=MBProgressHUDModeIndeterminate;
hub.labelText=@"Sending...";
[tempKeyboardWindow addSubview:hud];
[hud show:YES];

for ios 9 instead [[[UIApplication sharedApplication] windows] objectAtIndex:1] try use [[[UIApplication sharedApplication] windows] lastObject]

so it will be like this

UIWindow *tempKeyboardWindow = [[[UIApplication sharedApplication] windows] lastObject];
MBProgressHUD *hud=[[MBProgressHUD alloc] initWithWindow:tempKeyboardWindow];
hub.mode=MBProgressHUDModeIndeterminate;
hub.labelText=@"Sending...";
[tempKeyboardWindow addSubview:hud];
[hud show:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文