Get iPhone Status Bar Height

The statusBarFrame returns the frame in screen coordinates. I believe the correct way to get what this corresponds to in view coordinates is to do the following:

- (CGRect)statusBarFrameViewRect:(UIView*)view 
{
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];

    CGRect statusBarWindowRect = [view.window convertRect:statusBarFrame fromWindow: nil];

    CGRect statusBarViewRect = [view convertRect:statusBarWindowRect fromView: nil];

    return statusBarViewRect;
}

Now in most cases the window uses the same coordinates as the screen, so [UIWindow convertRect:fromWindow:] doesn’t change anything, but in the case that they might be different this method should do the right thing.

Leave a Comment