MBProgressHUD覆盖键盘
正好用到,标记一下!
来自:http://www.cnblogs.com/ruiq/archive/2012/04/19/2457702.html
发送微博的时候,需要用MBProgressHUD来覆盖窗口等待发送成功,但是无论如何键盘都覆盖不上。
于是各种研究,添加到view,添加到window,都无果。。想破了脑子,总觉得加到window都覆盖不了,这个比较奇葩
后来突然检查了一下window的count,发现居然有2个window!!!我印象中iphone应该只有一个window啊。。不过隐约想起谁说过iphone有时候会有多个window
最后把hud加到了第二个window下,覆盖成功。
遍历了一下第二个window的views,发现是里边装着键盘,就真相大白了
原来第二个window是用来装键盘的,把hud加到键盘所在的window下就能覆盖键盘了。
伪代码如下:
UIWindow *win=[[UIApplicationsharedApplication].windowsobjectAtIndex:1];
MBProgressHUD *hub=[[MBProgressHUDalloc] initWithWindow:win];
hub.mode=MBProgressHUDModeIndeterminate;
hub.labelText=@"发送中。。。";
[win addSubview:hub];
[hub show:YES];
[hub hide:YES afterDelay:3];
[hub release];
遍历views的结果如下:
2012-04-19 18:05:53.453 HudDemo[3736:f803] view0 is <UIPeripheralHostView: 0x689f550; frame = (0 228; 320 252); autoresizesSubviews = NO; layer = <UIPeripheralHostLayer: 0x68a93b0>>
2012-04-19 18:05:53.455 HudDemo[3736:f803] view1 is <UIKeyboardCornerView: 0x68aa1f0; frame = (0 473; 7 7); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x68aa230>>
2012-04-19 18:05:53.455 HudDemo[3736:f803] view2 is <UIKeyboardCornerView: 0x68aa3a0; frame = (313 473; 7 7); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x68aa3e0>>
2012-04-19 18:05:53.455 HudDemo[3736:f803] view3 is <MBProgressHUD: 0x6ab27a0; frame = (0 0; 320 480); alpha = 0; opaque = NO; autoresize = LM+RM+TM+BM; layer = <CALayer: 0x6abd860>>