mr.*_*r.b 15 iphone objective-c ios-simulator
我正在创建一个在控制器内部有少量元素的iphone应用程序(例如标签栏,uiview,uitoolbar等).一切正常,直到我遇到这个问题.当我的应用程序启动时,我接到一个电话,它显示了"呼叫状态栏",它破坏了ui.一些元素被推下,因为"呼叫状态栏"占据了顶部的空间.
这里有人知道如何解决这个问题吗?我是iPhone应用程序开发的新手.
非常感谢您的回复......
最好的祝福,
pro*_*255 22
dianz的解决方案工作正常,但如果您只想了解特定视图控制器内部的通知,则有点多余.
在application:didChangeStatusBarFrame:应用程序中调用委托方法后,UIApplicationDidChangeStatusBarFrameNotification通过发布委托[NSNotificationCenter defaultCenter].
application:didChangeStatusBarFrame:您可以UIApplicationDidChangeStatusBarFrameNotification直接从视图控制器添加观察者,而不是使用委托方法简单地重新发布自定义通知.
在MyCustomViewController中,您将添加类似于此的内容:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doSomething:)
UIApplicationDidChangeStatusBarFrameNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
现在您不再需要application:didChangeStatusBarFrame:在appDelegate中定义委托方法(除非您计划在状态栏更改大小时在appDelegate中执行某些操作).
与dianz的示例一样,您需要删除dealloc中的观察者
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
DLe*_*nde 12
你应该把这个函数放在appDelegate上,这会在状态栏改变时触发
- (void)application:(UIApplication *)application didChangeStatusBarFrame (CGRect)oldStatusBarFrame
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"trigger" forKey:@"frame"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"trigger" object:self userInfo:dict];
}
Run Code Online (Sandbox Code Playgroud)
此代码将发送名称为"trigger"的通知
将代码放置到视图控制器(例如:viewDidLoad等).如果有通知发送名称为"trigger",则监听
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dataReceived:)
name:@"trigger"
object:nil];
Run Code Online (Sandbox Code Playgroud)
并创建一个函数dataReceived:
- (void)dataReceivedNotification:(NSNotification *)notification {
NSDictionary *data = [notification userInfo];
// do something with data
}
Run Code Online (Sandbox Code Playgroud)
在代码的这一部分做一些事情,也许你改变标签栏,uiview框架,工具栏框架的框架
并且dealloc,在此代码中删除观察者
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10395 次 |
| 最近记录: |