Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

uiview - How to get the actual [UIScreen mainScreen] frame size?

I'm a bit annoyed. I have an app with the statusbar visible in the main window. Since I would like to setup my views and their frame sizes dynamically (perhaps the status bar takes up 40 pixels during a phone call, for example).

I can do one of the two:

[[UIScreen mainScreen] bounds];
[[UIScreen mainScreen] applicationFrame];

The really annoying this is these two output two different sets of values, each equally as useless.

bounds will output: {{0, 0}, {320, 480}} while
applicationFrame will output {{0, 20}, {320, 460}}

As you can see, bounds gives the correct y origin (0 starts from right below the statusbar) but then gives a height of 480, which is incorrect. It should be 460, since the statusbar is visible. Then we have applicationFrame which starts 20 pixels below the statusbar (so there's a cap), but then gives the correct height. But that's not very useful when it's then pushed down 20 pixels anyway.

Any help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually that is very usefull.
When you ask a UIScreen for it's Bounds you get the bounds of the screen, which is the whole device screen. (the status bar is part of the screen)
But if you ask a UIScreen to tell you where and how big can be the root view of your application asking for the applicationFrame is usefull. There is no direct relationship between the 2 calls except that the applicationFrame is returned in the UIScreen bounds coordinate system. (But the status bar is not part of your application, that explain the different result)

applicationFrame
The frame rectangle to use for your application’s window. (read-only)
@property(nonatomic, readonly) CGRect applicationFrame
Discussion
This property contains the screen bounds minus the area occupied by the status bar, if it is visible. Using this property is the recommended way to retrieve your application’s initial window size. The rectangle is specified in points.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...