Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MBProgressHUD cannot cover Keyboard

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?

like image 723
Smeegol Avatar asked Oct 18 '11 01:10

Smeegol


1 Answers

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.

like image 51
OpenThread Avatar answered Sep 20 '22 19:09

OpenThread