Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone- How to resize view when call status bar is toggled?

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,

like image 749
mr.b Avatar asked Oct 16 '10 01:10

mr.b


1 Answers

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];
}
like image 120
process255 Avatar answered Oct 05 '22 22:10

process255