I have been using the method below to get the status bar height. However I need to get the height when the view loads so I can adjust the height of my tableview accordingly. Using this method in viewDidLoad returns 0.
I have tried using it in viewDidAppear which works, however when I return to the view from a child view (as its part of a nav controller) it takes the height and adjusts it again, every time I return to the view.
So how can I get the height when the view loads to apply this adjustment without running into these issues?
-(CGRect)statusBarFrameViewRect
{
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect statusBarWindowRect = [self.view.window convertRect:statusBarFrame fromWindow: nil];
CGRect statusBarViewRect = [self.view convertRect:statusBarWindowRect fromView: nil];
return statusBarViewRect;
}
Thanks.
I was able to get the height of both the Status Bar and the Navigation Bar in
-viewDidLoad. If you are also transitioning in/out the status bar while loading this new view, you may want to register forUIApplicationWillChangeStatusBarFrameNotification. I can even get the status bar frame in-[appDelegate application:didFinishLaunchingWithOptions:]As an aside, I’d expect individual views to not have to care about the status bar, specifically, so this leads me to think you might be using the status bar as an overlay. If that’s the case (Photos.app does this), consider adjusting the
contentInsetinstead ofheight.