UIView框架比iPhone屏幕大
我在 XCode 中创建了一个新的基于 iPhone 视图的项目,并查看了生成的 xib,其名称为 myAppViewController.xib
。在该 xib 中,生成的视图的框架如下所示: { x = 160, y = 230, w = 320, h = 460 }
该视图应该填充整个屏幕,不包括状态栏。我希望视图的框架看起来像这样:对于旧款 iPhone,{ x = 0, y = 0, w = 240, y = 300 }
,以及 { x = 0, y = 0, w = 480, h = 600 }
用于视网膜显示。然而,我得到了上面那些奇怪的值。谁能向我解释一下这里发生了什么,它破坏了我其他项目中的一些绘图代码(要绘制的区域基于视图的框架)。
I have made a new iPhone View-based project in XCode, and I have a look at the xib generated, with the name myAppViewController.xib
. In that xib, the generated view's frame looks like this: { x = 160, y = 230, w = 320, h = 460 }
this view is supposed to fill the entire screen, excluding the status bar. I would expect the view's frame to look like this: { x = 0, y = 0, w = 240, y = 300 }
for the older iPhones, and { x = 0, y = 0, w = 480, h = 600 }
for the retina display. However, I get those weird values above. Can anyone please explain to me what is happening here, it is ruining some of my drawing code in my other project (the area to draw is based off of the frame of the view).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
视网膜显示屏实际上并没有增加视图的点大小。
当苹果推出它时,它区分了点和像素。视网膜显示屏具有更多像素,但点数相同。
代码中与 UIKit 相关的所有内容通常都以点为单位,因此不需要进行任何更改,100x100 的视图仍将是该大小。
我真的不明白你的问题,但框架值可以通过 bounds 属性和 center 属性修改......所以请检查你是否没有修改这些。
Retina display doesn't actually increase the point size of the view.
When Apple introduced it, it made a difference between points and pixels. Retina display has more pixels, but the same amount of points.
Everything in your code related to UIKit will generally be in points, so no changes are needed there, a view of 100x100 will still be that size.
I don't understand really your question but the frame value can be modified by the bounds property and the center property... so check if you're not modifying those.
框架矩形如下:
屏幕宽度为 320 像素宽 x 480 像素高。状态栏是20px。因此,您想要的矩形是:
无论是否有视网膜,设备都会根据需要进行转换。
Frame rects are as such:
the screen width is 320px wide by 480px tall. the status bar is 20px. thus the rect you would want is:
regardless of retina or not, the device will convert up as needed.
坐标以点为单位,而不是像素。无论屏幕分辨率如何,坐标系都是 320 X 480。
Coordinates are in points, not pixels. The coordinate system is 320 X 480, regardless of the resolution of the screen.