ios - 如何在 iOS 的状态栏和导航栏顶部添加子视图?
问题描述
我正在尝试在状态栏和导航栏之间添加一个子视图,所以我设置了 y 位置 = 0,然后我减小了 UIApplication Keywindow 的大小,以便它可以释放顶部的空间。
导航栏向下移动,没关系。但我也需要显示正确的状态栏。这是我的代码。
float yPosition = 0;
CGRect fr = CGRectMake(0, yPosition, UIScreen.mainScreen.bounds.size.width, 40);
runningCallView.frame = fr;
[UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 40, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height-40);
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:runningCallView];```
Can anyone please help on this. Thank you.
解决方案
我已经解决了这个问题。现在,我没有向下移动 keyWindow,而是向下移动了 rootviewController。
[UIApplication sharedApplication].keyWindow.rootViewController.view.frame = CGRectMake(0, shiftDownwards, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height-shiftDownwards);
并添加了一个状态栏子视图以在顶部显示一个假子视图。UiWindow 也需要是子类来检测额外添加的视图上的触摸。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
推荐阅读
- typescript - 将 VSCode linting 与 vue-cli linting 同步
- javascript - 通过 Javascript 中的 RegEx 逐步验证电子邮件地址
- python - 在其他参数之前调用带有默认参数的python函数?
- r - 在 R 中使用 quadprog 的 SVM
- azure-api-management - 如何保护后端 API 免受 Azure API 管理以外的调用
- docker - 集群上版本之间的领事问题(0.6 - 0.7.1)
- python - 如何设置 Google Cloud Function HTTP 响应的内容类型
- c++ - 使用单个条件变量暂停多个线程
- python - 在 Python 中编译用户的字典以获取搜索结果
- tensorflow - 一旦我激活 tensorflow env,Anaconda 提示就会崩溃