2011-07-27 245 views

回答

8

UIDeviceOrientation爲您提供有關物理設備本身的信息,同時UIInterfaceOrientation告訴你的是顯示視圖的方向。這些不需要匹配;當用戶使用方向鎖或者設備方向朝上時。

您可能想要檢查UIInterfaceOrientation以及UIViewController上的旋轉方法以確定視圖何時或應該旋轉。

+1

我希望在一年前知道的事情!我必須使用可以工作的設備方向來解決這個問題的整個解決方案,但是沒有涵蓋幾個角落案例。小時的頭痛......謝謝! – mtmurdock

2

UIDeviceOrientation指的是設備的物理方向,而UIInterfaceOrientation指的是用戶界面的方向。

因此,您需要設置的是autoResizeMask,以便在調整其超級視圖的大小時正確調整視圖的大小。爲視圖設置flexibleWidth和flexibleHeight。檢查http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html

而且 - 是指

UIDEVICE orientation

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation] 
+0

你上面的代碼是不正確的。您正在將設備方向分配給UIInterfaceOrientation變量。應該是'UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation],或者它應該是'UIInterfaceOrientation orientation = self.interfaceOrientation',其中self是UIViewController。 – mtmurdock