uiview - 如何获取实际的[UIScreen mainScreen]框架大小?

标签 uiview frame uiapplication

我有点生气。我有一个应用程序,其状态栏在主窗口中可见。因为我想动态设置我的 View 及其框架大小(例如,状态栏在通话期间可能占用 40 像素)。

我可以执行以下两个操作之一:

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

真正烦人的是这两个输出两组不同的值,每组都同样无用。

bounds 将输出:{{0, 0}, {320, 480}} while
applicationFrame 将输出 {{0, 20}, {320, 460}}

如您所见,bounds 给出了正确的 y 原点(0 从状态栏正下方开始),但随后给出的高度为 480,这是不正确的。它应该是 460,因为状态栏是可见的。然后我们有 applicationFrame ,它从状态栏下方 20 像素开始(因此有一个上限),但随后给出了正确的高度。但无论如何,当它被推低 20 像素时,这并不是很有用。

有什么帮助吗?

最佳答案

其实这非常有用。
当您向 UIScreen 询问其 Bounds 时,您将获得屏幕的边界,即整个设备屏幕。 (状态栏是屏幕的一部分)
但是,如果您要求 UIScreen 告诉您应用程序的 Root View 在哪里以及有多大,则要求 applicationFrame 是有用的。 除了在 UIScreenbounds 坐标系中返回 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.

关于uiview - 如何获取实际的[UIScreen mainScreen]框架大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5150794/

相关文章:

ios - 绘制 UIView 并转换为 UIImage

opengl - 如何使用 OpenGL 渲染到帧缓冲区而不在屏幕上显示?

iphone - 通知发生后 UILocalNotification 显示 View ?

ios - UIView addSubview 自动布局不工作

ios - 将目标添加到 super View 的 UIButton

objective-c - 将按钮(UIButton)添加到使用 drawRect : 绘制的自定义 tableview 单元格

latex - 在包含制表符环境的图形周围创建一个框

ios - UIViewController 的 subview 未显示

ios8 - 来自应用扩展的 openURL

iphone - 在 iPhone 底部添加 StatusBar