Question

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).

Was it helpful?

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:.

OTHER TIPS

You can check at development time if the view controller extends edges under bars looking at the following in your storyboard, selecting your view controller and searching into the Attributes Inspector:

Extend Edges

You could also check it programatically checking for the variables edgesForExtendedLayout and extendedLayoutIncludesOpaqueBars of your view controller.

Please check the following reference from Apple Docs for more information and detailed explanation Docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top