调整通话状态栏的大小?
如何根据笔尖上的通话状态栏调整视图大小?
我认为它只是设置调整大小属性,但它们没有为根 UIView 启用。
(我认为我的主要问题是我不知道这一切叫什么;除了谈论模拟器菜单命令之外,我在任何文档中都找不到对通话中状态栏的任何引用。)
How can I make my view resize in response to the in-call status bar from my nib?
I figured it would just be setting the resize properties, but they're not enabled for the root UIView.
(I think my main problem here is I don't know what any of this is called; I can't find any reference to the in-call status bar in any of the documentation except where it talks about the simulator menu command.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
只要状态栏发生变化,iOS 就会调用 viewController 的 viewWillLayoutSubviews 方法。 您可以覆盖它并根据新的边界调整您的子视图。
iOS will invoke your viewController's viewWillLayoutSubviews method whenever there is a change in status bar. You can override that and adjust your subviews according to the new bounds.
您正在寻找 -[UIApplication statusBarFrame],并且在 UIApplicationDelegate 中,您应该实现此委托方法,以便在状态栏的框架发生更改时收到通知:
You're looking for -[UIApplication statusBarFrame] and, in your UIApplicationDelegate, you should implement this delegate method to be notified of when the status bar's frame changes:
如果您没有设置根视图控制器,视图可能不会随着状态栏大小的变化自动调整大小。 我最初在我的应用程序委托中拥有此功能,并且我的应用程序在所有方面都工作正常,只是在通话期间它无法正确调整大小。
我将上面的行更改为这一行,现在我的应用程序在通话期间自动调整大小。
在日志中看到此内容并调查原因后,我发现了此修复程序。
A view may not resize automatically with status bar size changes if you do not have a root view controller set. I originally had this in my app delegate, and my app worked properly in all regards except that it would not resize correctly during phone calls.
I changed the above line to this, and now my app resizes automatically during calls.
I discovered this fix after seeing this in the log and investigating the cause.
当我的应用程序在后台运行并且我按 command + T 时,这对我来说非常有效。在我的场景中,根控制器是我的选项卡栏控制器,我正在每个选项卡内重新调整我的导航控制器。
}
this works for me perfectly when my application is running in background and I press command + T. In my scenario , the root controller is my tab bar controller and I am readjusting my nav controller inside each tab.
}
当您说“根 UIView 未启用调整大小属性”时,您是什么意思?
通话中的状态栏没有任何特殊的名称,我认为它周围没有任何 API 或通知。 相反,您的视图应该简单地设置为正确自动调整大小。
尝试在 Xcode 中创建一个新的基于导航的应用程序,并研究 RootViewController.xib 中表格视图的自动调整大小设置。 希望您会看到 Apple 的设置与您在项目中设置的内容之间存在差异。
What do you mean when you say that 'the resize properties aren't enabled for the root UIView'?
The in-call status bar doesn't have any particular special designation, and I don't think there are any APIs or notifications around it. Instead, your views should simply be set up to autoresize correctly.
Try creating a new navigation-based app in Xcode and study the autoresize settings on the table view in RootViewController.xib. Hopefully you'll see a delta between what Apple's set and what you've set in your project.
对于像 UITableView 这样的视图,您通常需要更改表格单元格高度,除了实现 application:didChangeStatusBarFrame: 之外,没有其他方法可以做到这一点。 但这没什么大不了的,如果需要,您可以将行高设置为非整数值。
For views like UITableView you'll typically need to change the table cell height, and there's no other way to do it except to implement application:didChangeStatusBarFrame:. But it's no biggie, and you can set the row height to non-integer values if you need to.
状态栏更改框架的通知是
UIApplicationWillChangeStatusBarFrameNotification
注册为观察者:
[[NSNotificationCenter defaultCenter] addObserver:self
选择器:@selector(statusBarFrameWillChange:)名称:UIApplicationWillChangeStatusBarFrameNotification对象:nil];
然后响应处理程序中的更改:
- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// 响应变化
即使自动
布局设置正确,您也可能需要响应更改。 例如,根据屏幕中给定空间计算单元格高度的表格视图可能需要在状态栏更改后
reloadData
。文档
The notification for status bar changing frame is
UIApplicationWillChangeStatusBarFrameNotification
Register as an observer:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(statusBarFrameWillChange:)name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
Then respond to change in your handler:
- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// respond to changes
}
Even with autolayout setup correctly, you may need to respond to changes. For example, a table view that calculates its cell height based on the given space in the screen would may need to
reloadData
after the status bar changed.Documentation
我也遇到了同样的问题。 我所做的就是这个。
我希望我说清楚了。
I was having the same problem. What I did was this.
I hope I was clear.
如果您以编程方式设置视图框架,则必须手动更新视图。
这将为您提供状态栏的新高度,并使用它可以相应地更新框架。
You will have to update the views manually if you are setting your view frames programatically
This gives you the new height of the status bar and using this you can update your frames accordingly.
解决方案是确保您已设置窗口键:
如果您不这样做,则子视图不会自动调整大小,但据我所知,没有其他症状。
The solution is to ensure you have made your window key:
If you don't do that the subview does not get resized automatically, but there are no other symptoms as far as I know.
之前发布的解决方案都不适合我。 对我有用的是我没有为我的观点正确设置约束。 在我的情况下,我的视图中有两个不同的容器视图。
底部(在列表中)容器视图是一个
UITableView
,它没有正确滚动到表格底部。 原因是通话中状态栏的偏移导致 UITableView 的原点(左上角)发生变化,但大小仍保持不变。 这意味着桌子的底部超出了屏幕!解决方案是正确设置自动调整大小高度约束。 在下面的屏幕截图中,它是“自动调整大小”框中间的垂直箭头。
None of the solutions posted before worked for me. What did work for me was that I didn't have my constraints set up properly for my views. In my situation, I had two different container views within my view.
The bottom (in the list) container view was a
UITableView
, which was not scrolling correctly to the bottom of the table. The reason was that the offset of the in-call status bar was causing the origin (top-left corner) of theUITableView
to change, but the size would remain this same. This meant that the bottom of the table was off screen!The solution was to correctly set the Autoresizing height constraint properly. In the screenshot below, it is the vertical arrows in the middle of the Autoresizing box.