【发布时间】:2011-05-14 05:11:18
【问题描述】:
我的目标是在我的 iPhone 应用顶部的状态栏上方绘制一个不可见的按钮(尺寸 320*20 像素)。
无论我尝试什么,都有问题:
例如,我尝试创建一个新视图。当我想将视图放在我的应用顶部时,它总是消失在状态栏后面而不是在它前面!
我在 Stackoverflow 上发现了另一个好主意: Add UIView Above All Other Views, Including StatusBar 即使不推荐使用第二个 UIWindow,我也尝试实现它。它按我的意愿工作,直到我注意到一个问题:键盘在需要时不再出现(例如在单击文本框时)!
我该如何解决这个问题?还是有更好的方法来解决我的问题?这是我创建第二个窗口的代码:
// Create window
statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
[statusWindow makeKeyAndVisible];
// Create statusBarButton
statusBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect buttonFrame2 = statusBarButton.frame;
buttonFrame2.size = CGSizeMake(320,20);
statusBarButton.frame = buttonFrame2;
[statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside];
// Place button into the new window
[statusWindow addSubview:statusBarButton];
【问题讨论】:
标签: iphone uiview keyboard statusbar uiwindow