如何获得实际的[UIScreen mainScreen]帧大小? [英] How to get the actual [UIScreen mainScreen] frame size?

查看:97
本文介绍了如何获得实际的[UIScreen mainScreen]帧大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点生气.我有一个带有状态栏的应用程序,该应用程序在主窗口中可见.由于我想动态设置视图及其帧大小(例如,在通话期间状态栏可能占用40像素).

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将输出:{{0, 0}, {320, 480}}
applicationFrame将输出{{0, 20}, {320, 460}}

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

如您所见,bounds给出了正确的y原点(0从状态栏的右下角开始),然后给出了480的高度,这是不正确的.因为状态栏是可见的,所以它应该是460.然后我们有applicationFrame,它开始于状态栏下方20个像素(因此有一个上限),然后给出正确的高度.但这在将像素向下推20个像素时不是很有用.

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.

有帮助吗?

推荐答案

实际上这非常有用.
当您要求UIScreenBounds时,您会得到屏幕的边界,即整个设备屏幕. (状态栏是屏幕的一部分)
但是,如果您要求UIScreen告诉您要求applicationFrame的应用程序的根视图在什么地方以及可以显示多大,这很有用. 这两个调用之间没有直接关系,只是在UIScreen bounds坐标系中返回了applicationFrame. (但是状态栏不是您的应用程序的一部分,它解释了不同的结果)

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
用于应用程序窗口的框架矩形. (只读)
@property(非原子,只读)CGRect applicationFrame
讨论
此属性包含屏幕边界减去状态栏所占据的区域(如果可见).建议使用此属性来检索应用程序的初始窗口大小.矩形以点为单位.

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.

这篇关于如何获得实际的[UIScreen mainScreen]帧大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆