Search code examples
objective-cios7statusbar

How to tell if a view's viewcontroller extends beneath statusbar in iOS7


How can i tell if a view's viewcontroller extends beneath the status bar in iOS7?

I guess the first problem is getting the view's current viewcontroller, then how can I tell if that viewcontroller extends beneath the status bar?

Clarification / Reasoning I need to know this because I am adding an info panel to the view that slides in from the top and needs to fill up the view underneath the status bar. Depending on the edgesForExtendedLayout property of the viewController a yPosition of 0 can either be the very top of the window or just underneath the statusbar. I need to know what I'm dealing with so I can offset the panel accordingly.

Example A: Showing the panel in a view contained within a simple UIViewController (a yPosition of 0 will put the panel underneath the status bar)

Example B: showing the panel in a view contained within a UINavigationController with an opaque navigationBar (a yPosition of 0 will put the panel just below the status bar. an actual device yPosition of 20).


Solution

  • If you know what view controller you are working with, you can get the rect within the window.

    CGRect rectInWindow = [self.view convertRect:self.view.bounds toView:self.view.window];
    

    if rectInWindow.orig.y == 0 and rectInWindow.size.height == self.view.window.bounds.size.height, then you are extended.

    NOTE: This only works after -viewDidAppear:.