我的目标是在我的 iPhone 应用程序顶部的状态栏上方绘制一个不可见的按钮(尺寸 320*20 像素)。
无论我尝试什么,都有问题:
例如,我尝试创建一个新视图。当我想将视图放在我的应用程序的顶部时,它总是消失在状态栏的后面而不是在它的前面!
我在 Stackoverflow 上发现了另一个好主意: 在所有其他视图之上添加 UIView,包括 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];