and*_*eas 7 iphone keyboard statusbar uiview uiwindow
我的目标是在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)
在 - [UIWindow makeKeyAndVisible]的文档中:
这是一种方便的方法,使接收器成为主窗口并将其显示在其他窗口的前面.您还可以使用UIView的继承隐藏属性隐藏和显示窗口.
"关键窗口"是获取某些输入事件的关键窗口; 非键窗口中的文本字段可能不起作用.你可以做两件事:
statusWindow.hidden = NO改为设置(但我不明白为什么默认会隐藏它).我不认为你可以"在其他窗口前显示它",如-makeKeyAndVisible; windows没有superview你可以调用-bringSubviewToFront:在IIRC上.在AppDelegate文件中
self.window.windowLevel = UIWindowLevelStatusBar;
Run Code Online (Sandbox Code Playgroud)
或在任何其他类别
[AppDelegate appDelegate].window.windowLevel = UIWindowLevelStatusBar;
Run Code Online (Sandbox Code Playgroud)
如果你想让状态栏再次位于顶部你可以设置
self.window.windowLevel = UIWindowLevelNormal;
Run Code Online (Sandbox Code Playgroud)
如果其他用户想要实现这个,那么我的解决方案是:
// Create window
statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
// Dont make the statusWindow keyWindow or the keyboard won't work!
// [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];
// Instead, add this:
[window makeKeyAndVisible]; // has to be main window of app
statusWindow.hidden = NO; // without this the statusWindow won't appear
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15371 次 |
| 最近记录: |