MBProgressHud no puede cubrir el teclado
-
22-10-2019 - |
Pregunta
Cuando intento mostrar un MBProgressHud mientras el teclado también se muestra, uso el código a continuación, pero el objeto HUD no puede cubrir el teclado:
SNSSharerAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
HUD = [[MBProgressHUD showHUDAddedTo:delegate.window animated:YES] retain];
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = @"Posting...";
[HUD show:YES];
Pensé que el objeto HUD se muestra frente a la ventana del delegado, el teclado también se muestra, así que lo que agregó el último, que está al frente. ¿Me equivoco?
Solución
Agregue HUD a la segunda ventana que contiene el teclado. Cuando se muestra el teclado, hay dos instancias de Uiwindow en la aplicación. El primero es la ventana normal, la segunda es la ventana del teclado Temp. Código:
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];
Probado en iOS4.3 e iOS5.x, realmente funciona.
Otros consejos
para iOS 9 en su lugar [[[UIAPplication SharedApplication] Windows] ObjectatIndex: 1] Intente usar [[UIAPPLICATION SHARTEPAPLAY] Windows] LastObject
Entonces será así
UIWindow *tempKeyboardWindow = [[[UIApplication sharedApplication] windows] lastObject];
MBProgressHUD *hud=[[MBProgressHUD alloc] initWithWindow:tempKeyboardWindow];
hub.mode=MBProgressHUDModeIndeterminate;
hub.labelText=@"Sending...";
[tempKeyboardWindow addSubview:hud];
[hud show:YES];