开发者

Detect when an added subview's frame's origin is behind the status bar

I am adding subviews to the top of my view controllers, setting the added frame's origin's y to 0

aView.frame.origin.y = 0.0;

On one instance, the view appeared behind the status bar. This can be corrected easily by setting origin.y = 20.0;

Regardless of what the cause may be, how can I detect if I need to set it to 20.0 or not? In other words,开发者_StackOverflow how can I find out if the top of the page is behind the status bar or not?


You can peek into window.screen.applicationFrame to see coordinates, and at UIApplication's statusBarOrientation and statusBarHidden properties. But conditionally setting your frame top to 0 or 20 isn't really the solution - you want your frames to be set up so that it does the right thing without you having to change it. 0,0 should always be the top-left visible corner of your view.

If you used the view-based application template when you created your project, nearly everything should be set up correctly - just make sure that you specify a Gray or Black status bar in your XIB.

For programmatically created view controllers that you add directly to the Window, you might need:

myViewController.frame = window.screen.applicationFrame;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜