8

我的观点有错误的维度。我只运行横向,但视图报告纵向尺寸“视图宽度 = 768.000000 高度 = 1024.000000”有什么想法可以解决这个问题吗?我玩过我尝试过的自动旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

它在视图上看起来不错,但尺寸确实让我的应用程序混乱。

4

1 回答 1

13

你永远不应该frame用来告诉你自己的维度。 frame相对于父容器视图。要查找相对于您的视图自己的坐标系的尺寸,请使用boundsself.view.bounds

例如,父视图可能会看到宽度 = 768 和高度 = 1024 的子视图,但旋转 90 度变换。这就是父视图如何看待子视图,这就是它的意义self.view.frame所在。宽度 = 1024 和高度 = 768 的子视图反映在视图在其自己的坐标系中如何看待自己,即self.view.bounds

于 2012-11-17T02:09:57.577 回答