我正在创建一个 iphone 应用程序,其中 Controller 内的元素很少(例如标签栏、uiview、uitoolbar 等)。一切正常,直到我遇到这个问题。当我的应用程序启动时,我接到了一个电话,它显示了“通话状态栏”,这破坏了用户界面。一些元素被下推,因为“调用状态栏”占用了顶部的空间。
这里有人知道如何解决这个问题吗?我是 iPhone 应用程序开发的新手。
非常感谢您的回复...
最好的问候,
最佳答案
dianz 的解决方案工作得很好,但如果您只对了解特定 View Controller 内部的通知感兴趣,则它有点多余。
在委托(delegate)方法 application:didChangeStatusBarFrame:
被调用后,Application Delegate UIApplicationDidChangeStatusBarFrameNotification
通过 [NSNotificationCenter defaultCenter]
发布。
您可以直接从 View Controller 向 UIApplicationDidChangeStatusBarFrameNotification
添加观察者,而不是使用委托(delegate)方法 application:didChangeStatusBarFrame:
简单地重新发布自定义通知。
在 MyCustomViewController 中,您将添加与此类似的内容:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doSomething:)
UIApplicationDidChangeStatusBarFrameNotification
object:nil];
现在您不再需要在 appDelegate 中定义 application:didChangeStatusBarFrame:
委托(delegate)方法(除非您计划在状态栏更改大小时在 appDelegate 中执行某些操作)。
与dianz的例子一样,你需要在dealloc中移除观察者
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
关于Iphone-切换通话状态栏时如何调整 View 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3947226/