我的self.view有错误的尺寸 [英] My self.view has the wrong dimensions
问题描述
我的观点有错误的尺寸。我正在运行景观,但视图报告纵向尺寸查看宽度= 768.000000高度= 1024.000000任何想法如何解决?我玩过我试过的autorotate
My view has the wrong dimensions. I am running a Landscape only but the view is reporting portrait dimensions "View Width = 768.000000 Height = 1024.000000" Any Ideas how to fix that? I have played around with the autorotate I have tried
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
和
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
它在视图上看起来很好,但尺寸确实在弄乱我的应用。
It looks fine on the view but have the dimensions are really messing with my app.
推荐答案
你永远不应该使用 frame
来告诉你自己的维度。 frame
相对于父容器视图。要查找与视图自身坐标系相关的维度,请使用 bounds
: self.view.bounds
You should never use frame
to tell your own dimension. frame
is relative to the parent container view. To find the dimension with respect to your view's own coordinate system, use bounds
: self.view.bounds
例如,父视图可能会看到子视图的宽度= 768,高度= 1024,但旋转90度变换。这是父视图查看子视图的方式,这就是 self.view.frame
的内容。宽度= 1024和高度= 768的子视图反映在视图如何在自己的坐标系中看到自己,即 self.view.bounds
For example, the parent view may see the child view having width = 768 and height = 1024, but with a rotate 90 degree transform. This is how the parent view sees the child view, and this is what self.view.frame
is about. The child view having a width = 1024 and height = 768 is reflected by how a view sees itself in its own coordinate system, which is self.view.bounds
这篇关于我的self.view有错误的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!