我的self.view尺寸错误

问题描述:

我的视图尺寸错误。我只运行横向,但视图报告纵向尺寸“视图宽度= 768.000000高度= 1024.000000”任何想法如何解决这个问题?我已经打得四处自动旋转我曾尝试我的self.view尺寸错误

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

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

它看起来就认为很好,但有尺寸确实与我的应用程序搞乱。

+0

如何获取视图的大小? – yuf

+0

self.view.frame.size.width。等等。 – Jonathan

+0

你什么时候读这个值? – yuf

你不应该使用frame来告诉你自己的维度。 frame是相对于父容器视图。要了解关于您的视图自己的坐标系中的尺寸,使用boundsself.view.bounds

例如,父视图可以看到其子视图宽度= 768和高度= 1024,但具有旋转90度的变换。这就是父视图如何看待子视图,这就是self.view.frame的内容。具有宽度= 1024和高度= 768的子视图通过视图在其自己的坐标系中看到自身的方式反映出来,即self.view.bounds

+0

我尝试使用边界,但我仍然得到相同的结果。我在想,这个看法可能不知道iPad是在风景中。我不知道。 – Jonathan

+1

尝试在'touchesBegan'中打印出来,看看你是否看到相同的值? –

+0

这工作,这超级怪异你知道它为什么这样做吗? – Jonathan