UIDevice方向和UIInterface方向有什么区别?

May*_*ank 6 ios

UIDevice方向和UIInterface方向有什么区别?

UIDevice方向: -

    [[UIDevice currentDevice] orientation]
Run Code Online (Sandbox Code Playgroud)

UIInterface方向: -

    [[UIApplication sharedApplication] statusBarOrientation]
Run Code Online (Sandbox Code Playgroud)

Sub*_*bin 6

设备方向是设备当前所处的方向。我们可以通过这个调用获得设备方向:

[[UIDevice currentDevice] orientation]
Run Code Online (Sandbox Code Playgroud)

这将返回以下状态之一: UIDeviceOrientationUnknown UIDeviceOrientationPortrait UIDeviceOrientationPortraitUpsideDown UIDeviceOrientationLandscapeLeft UIDeviceOrientationLandscapeRight UIDeviceOrientationFaceUp UIDeviceOrientationFaceDown

有FaceUp 和FaceDown 两种状态。当设备平放在桌子上时,其中一个将被退回。所以在这种情况下,我们不知道如何布局我们的 UI。

诀窍是获取状态栏的 UIInterfaceOrientation。因为我们希望我们的 GUI 与状态栏处于相同的方向。要从状态栏获取 UIInterfaceOrientation,我们使用以下代码:

[[UIApplication sharedApplication] statusBarOrientation]
Run Code Online (Sandbox Code Playgroud)

  • 恕我直言,这不能回答实际问题,因为您没有解释 UIInterfaceOrientation 是什么。 (5认同)