2013-06-20 66 views
1

我希望我的iPhone應用程序在全局上表現得好像只有UIInterfaceOrientationPortrait被允許。 但同時我希望它知道物理方向以便以特定的方式進行反應,只能在顯示屏的有限區域內進行反應。 我怎樣才能得到這個?UIInterfaceOrientation問題

我做了一些測試,使用UIViewController的self.interfaceOrientation iVar,但似乎沒有工作,因爲這個變量沒有改變。

回答

1

首先,做[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]。然後註冊UIDeviceOrientationDidChangeNotification。當您收到通知時,請檢查[UIDevice currentDevice].orientation以瞭解設備的物理方向。

您一定要閱讀這些API的文檔,因爲它包含一些重要的警告。

另請注意,設備方向返回爲UIDeviceOrientation,與UIInterfaceOrientation不同。請記住這個信息從UIInterfaceOrientation文檔:

您使用在statusBarOrientation財產這些常數和setStatusBarOrientation:animated:方法。請注意,UIDeviceOrientationLandscapeRight分配給UIInterfaceOrientationLandscapeLeft,而UIDeviceOrientationLandscapeLeft分配給UIInterfaceOrientationLandscapeRight;原因在於旋轉設備需要在相反的方向旋轉內容。

相關問題