[UIDevice currentDevice].orientation
返回一个UIDeviceOrientation
:
该属性的值是一个常数,指示设备的当前方向。此值表示设备的物理方向,可能与应用程序用户界面的当前方向不同。
您的getWidthAndHeightForOrientation
函数需要一个UIInterfaceOrientation
参数:
应用程序用户界面的方向。
这些类型虽然相关,但不是一回事。您可以使用 . 从任何视图控制器访问当前界面方向self.interfaceOrientation
。UIInterfaceOrientation
有 4 个可能的值,而UIDeviceOrientation
有 9 个:
typedef NS_ENUM(NSInteger, UIDeviceOrientation) {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top
UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right
UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp, // Device oriented flat, face up
UIDeviceOrientationFaceDown // Device oriented flat, face down
};
// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa).
// This is because rotating the device to the left requires rotating the content to the right.
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
};