3 回答

TA貢獻1887條經(jīng)驗 獲得超5個贊
您可以通過3種方式獲得方向:
UIInterfaceOrientation orientation = self.interfaceOrientation;
返回UIInterfaceOrientation,接口的當前方向。它是UIViewController中的一個屬性,只能在UIViewController類中訪問它。UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
返回UIInterfaceOrientation,即應(yīng)用程序狀態(tài)欄的當前方向。您可以在應(yīng)用程序的任何位置訪問該屬性。我的經(jīng)驗表明,這是檢索真實界面方向的最有效方法。UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
返回UIDeviceOrientation,設(shè)備方向。您可以在應(yīng)用程序的任何位置訪問該屬性。但請注意,UIDeviceOrientation并不總是UIInterfaceOrientation。例如,當您的設(shè)備位于普通表上時,您可以獲得意外的價值。

TA貢獻1789條經(jīng)驗 獲得超10個贊
如果您只是關(guān)心設(shè)備是橫向還是縱向,那么viewcontroller上有一些不錯的便利方法:
UIDeviceOrientationIsLandscape(self.interfaceOrientation) UIDeviceOrientationIsPortrait(self.interfaceOrientation)

TA貢獻1807條經(jīng)驗 獲得超9個贊
在viewcontroller中,您只需使用代碼:
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
UIInterfaceOrientation是一個枚舉:
typedef enum { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeRight} UIInterfaceOrientation;
- 3 回答
- 0 關(guān)注
- 566 瀏覽
添加回答
舉報