我有一個自定義的CALayer,它應該在不同的界面方向上看起來不同。 有沒有一種方法可以訪問我使用此CALayer的View Controller的interfaceOrientation?如何訪問自定義CALayer中的interfaceOrientation?
或者我將不得不在自定義圖層中設置一個屬性,指示每次改變時的當前方向?
我有一個自定義的CALayer,它應該在不同的界面方向上看起來不同。 有沒有一種方法可以訪問我使用此CALayer的View Controller的interfaceOrientation?如何訪問自定義CALayer中的interfaceOrientation?
或者我將不得不在自定義圖層中設置一個屬性,指示每次改變時的當前方向?
您可以在自定義圖層上設置屬性。
或者您可以給自定義圖層引用視圖控制器的屬性,以便當圖層需要知道時,它可以向視圖控制器請求接口方向。
或者您可以讓您的視圖控制器在旋轉時發佈NSNotification
,並讓圖層觀察通知。
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
返回UIInterfaceOrientation
,應用程序狀態欄的當前方向。
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
返回UIDeviceOrientation,設備方向。但請注意,UIDeviceOrientation
並不總是UIInterfaceOrientation
。例如,當您的設備在普通桌面上時,您可能會收到意外的值。
http://stackoverflow.com/questions/634745/iphone-orientation/3897243#3897243 – beryllium 2012-02-15 09:24:14