Iphone-切换通话状态栏时如何调整 View 大小?

标签 iphone objective-c ios-simulator

我正在创建一个 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/

相关文章:

iphone - 在 Facebook 中注销

iphone - 适用于iPhone 5和iPhone 4的CGRectMake

ios - 刷新 TableView ?

xcode - 应用程序在每秒运行时收到 SIGABRT

iphone - iPhone 自动化测试

iphone - 如何通过 Xcode 在我的设备上运行发布配置

iphone - UIView - 居中对齐 UIView 的所有内容?

c++ - 从 .cpp 文件调用 .mm 函数的链接器错误

ios - 如何使用for循环在NSMUtableArray中添加对象

Xcode 7 中的 iOS 6 和 7 模拟器