答案 0 :(得分:8)
答案 1 :(得分:3)
我建议使用UIDeviceOrientationIsValidInterfaceOrientation(orientation)
它会告诉您它是否是有效的方向(有效的是横向或纵向,而不是FaceUp / FaceDown / UnKnown)。然后你就可以把它看作是它的肖像,如果它是未知的。
我就是这样做的:
if (UIDeviceOrientationIsValidInterfaceOrientation(interfaceOrientation) && UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
// handle landscape
} else {
// handle portrait
}
答案 2 :(得分:0)
[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
};