I'm creating an iphone app with few elements inside the controller (e.g tab bar, uiview, uitoolbar, etc..). Everything works fine until I encountered this problem. While my application is launched, I received a call and it shows the "Call Status Bar" which ruined the ui. Some elements are pushed down because the "Call Status Bar" is taking space at the top.
Anybody here have an idea on how to fix this issue? I'm new to iPhone app development.
Your reply is greatly appreciated...
Best Regards,
You should put this function on appDelegate, this will trigger when the status bar change
- (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];
}
This Code will send Notification with the name "trigger"
Place a code to your view Controller (e.g: viewDidLoad, etc..) this listen if there are notification send with a name "trigger"
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dataReceived:)
name:@"trigger"
object:nil];
And create a function dataReceived:
- (void)dataReceivedNotification:(NSNotification *)notification {
NSDictionary *data = [notification userInfo];
// do something with data
}
do something on this part of the code, maybe you change the frame of your tab bar, uiview frame, toolbar frame
And in dealloc
, put this code to remove the observer
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
dianz's solutio works just fine but is a bit redundant if you are only interested in knowing about the notification inside of a specific view controller.
After the delegate method application:didChangeStatusBarFrame:
is called in the Application Delegate UIApplicationDidChangeStatusBarFrameNotification
is posted through [NSNotificationCenter defaultCenter]
.
Instead of using the delegate method application:didChangeStatusBarFrame:
to simply repost a custom notification you can add an observer to UIApplicationDidChangeStatusBarFrameNotification
directly from your view controller.
In MyCustomViewController you would add something similar to this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doSomething:)
UIApplicationDidChangeStatusBarFrameNotification
object:nil];
Now you no longer need to define the application:didChangeStatusBarFrame:
delegate method in appDelegate (unless you plan to do something in the appDelegate when the status bar changes size).
As with dianz's example you need to remove the observer in dealloc
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Basically what you normally do is try to set up the autoresize flags of all your ui elements in interface builder so that when the main view is "squashed" by the call status bar everything will still look reasonable. It's a little hard to explain how to do all of this in one message, but I recommend creating a view in IB, placing some subviews in it, then resizing the main view while playing with the autoresize flags to get a feel for how the flags work. The autoresize flags are in Command-3 (size inspector).
You can also set wantsFullScreenLayout
in the main view controller to YES to cause the view to take up the whole screen, including the area under the status bar, but then you'll have to make sure not to place anything under the status bar and the call status bar will overlap anything too close to it, of course.
for me, whenever the status bar is enlarged, the -(void)viewWillLayoutSubviews is always called. This is perfect for me because all my subview setFrame code is in this function.