2012-11-16 70 views
8

我的視圖尺寸錯誤。我只運行橫向,但視圖報告縱向尺寸「視圖寬度= 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

回答

13

你不應該使用frame來告訴你自己的維度。 frame是相對於父容器視圖。要了解關於您的視圖自己的座標系中的尺寸,使用boundsself.view.bounds

例如,父視圖可以看到其子視圖寬度= 768和高度= 1024,但具有旋轉90度的變換。這就是父視圖如何看待子視圖,這就是self.view.frame的內容。具有寬度= 1024和高度= 768的子視圖通過視圖在其自己的座標系中看到自身的方式反映出來,即self.view.bounds

+0

我嘗試使用邊界,但我仍然得到相同的結果。我在想,這個看法可能不知道iPad是在風景中。我不知道。 – Jonathan

+1

嘗試在'touchesBegan'中打印出來,看看你是否看到相同的值? –

+0

這工作,這超級怪異你知道它爲什麼這樣做嗎? – Jonathan