通过编程视图创建避免硬编码iPhone屏幕大小 [英] Avoid hardcoding iPhone screen size with programmatic view creation

查看:126
本文介绍了通过编程视图创建避免硬编码iPhone屏幕大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查找如何以编程方式创建视图,并找到以下示例代码:

I was looking up how to create a view programmatically and found the following example code:

self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];

这很好用,除了我不喜欢它硬编码屏幕大小。有没有办法查看屏幕的大小?有人提出的一个重点是,如果应用程序在通话过程中运行,那么由于绿色的返回呼叫栏,屏幕会略小一些。

This works great, except I don't like that it hardcodes the size of the screen. Is there a way to look up the size of the screen? An important point someone brought up is that if the app is running during a phone call then the screen will be slightly smaller because of the green "return to call" bar.

推荐答案


有没有办法在屏幕上查找
的大小?

Is there a way to look up the size of the screen?

是的:

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];




applicationFrame

applicationFrame

如果
可见,则此属性
包含屏幕边界减去状态栏占用的
区域。使用此属性是
建议的方法来检索
应用程序的初始窗口大小。
矩形以磅为单位指定。

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.

这篇关于通过编程视图创建避免硬编码iPhone屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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