我的self.view尺寸错误
问题描述:
我的视图尺寸错误。我只运行横向,但视图报告纵向尺寸“视图宽度= 768.000000高度= 1024.000000”任何想法如何解决这个问题?我已经打得四处自动旋转我曾尝试我的self.view尺寸错误
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
和
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
它看起来就认为很好,但有尺寸确实与我的应用程序搞乱。
答
你不应该使用frame
来告诉你自己的维度。 frame
是相对于父容器视图。要了解关于您的视图自己的坐标系中的尺寸,使用bounds
:self.view.bounds
例如,父视图可以看到其子视图宽度= 768和高度= 1024,但具有旋转90度的变换。这就是父视图如何看待子视图,这就是self.view.frame
的内容。具有宽度= 1024和高度= 768的子视图通过视图在其自己的坐标系中看到自身的方式反映出来,即self.view.bounds
如何获取视图的大小? – yuf
self.view.frame.size.width。等等。 – Jonathan
你什么时候读这个值? – yuf