我的目标是在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];
Run Code Online (Sandbox Code Playgroud)