ios 如何获取iOS设备屏幕高度和宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14135207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:43:16  来源:igfitidea点击:

How to get iOS device screen height and width

iosobjective-cuiscreen

提问by colindunn

Possible Duplicate:
IPhone/IPad: How to get screen width programmatically?
How to get orientation-dependent height and width of the screen?

可能重复:
iPhone/iPad:如何以编程方式获取屏幕宽度?
如何获得与方向相关的屏幕高度和宽度?

Accounting for the various iOS devices and orientations, what is the simplest approach to getting the current screen resolution, including height and width?

考虑到各种 iOS 设备和方向,获取当前屏幕分辨率(包括高度和宽度)的最简单方法是什么?

回答by Srikar Appalaraju

UIScreenis your friend here.

UIScreen是你的朋友吗?

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

回答by P.J

CGRect screenBounds = [[UIScreen mainScreen] bounds];

That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.

这将为您提供整个屏幕的分辨率(以点为单位),因此对于 iPhone,它通常为 320x480。即使 iPhone4 有更大的屏幕尺寸,iOS 仍然返回 320x480 而不是 640x960。这主要是因为较旧的应用程序中断。

Hope it helps you..

希望能帮到你。。