我希望我的iPhone應用程序在全局上表現得好像只有UIInterfaceOrientationPortrait被允許。 但同時我希望它知道物理方向以便以特定的方式進行反應,只能在顯示屏的有限區域內進行反應。 我怎樣才能得到這個?UIInterfaceOrientation問題
我做了一些測試,使用UIViewController的self.interfaceOrientation iVar,但似乎沒有工作,因爲這個變量沒有改變。
我希望我的iPhone應用程序在全局上表現得好像只有UIInterfaceOrientationPortrait被允許。 但同時我希望它知道物理方向以便以特定的方式進行反應,只能在顯示屏的有限區域內進行反應。 我怎樣才能得到這個?UIInterfaceOrientation問題
我做了一些測試,使用UIViewController的self.interfaceOrientation iVar,但似乎沒有工作,因爲這個變量沒有改變。
首先,做[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]
。然後註冊UIDeviceOrientationDidChangeNotification
。當您收到通知時,請檢查[UIDevice currentDevice].orientation
以瞭解設備的物理方向。
您一定要閱讀這些API的文檔,因爲它包含一些重要的警告。
另請注意,設備方向返回爲UIDeviceOrientation
,與UIInterfaceOrientation
不同。請記住這個信息從UIInterfaceOrientation
文檔:
您使用在
statusBarOrientation
財產這些常數和setStatusBarOrientation:animated:
方法。請注意,UIDeviceOrientationLandscapeRight
分配給UIInterfaceOrientationLandscapeLeft
,而UIDeviceOrientationLandscapeLeft
分配給UIInterfaceOrientationLandscapeRight
;原因在於旋轉設備需要在相反的方向旋轉內容。