当我尝试NSLog一个iPad的方向时,为什么我会得到整数值?

时间:2011-11-07 00:56:58

标签: xcode ipad integer orientation

只是想知道为什么我在尝试记录iPad的方向时会得到整数值。是否有资源告诉我每个值的含义是什么?我从1到8得到了任何东西。我只觉得有4个可能的方向,所以我很困惑。

1 个答案:

答案 0 :(得分:1)

考虑到文档显示,我不确定8个不同的值

typedef enum {
   UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
   UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
   UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
   UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;

您可以在记录方向之前将其记录下来并查看它的位置。

NSLog(@"UIInterfaceOrientationPortrait-%d\n\
UIInterfaceOrientationPortraitUpsideDown-%d\n\
UIInterfaceOrientationLandscapeLeft-%d\n\
UIInterfaceOrientationLandscapeRight-%d", UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight);

有方便的方法来测试特定的方向,例如

UIInterfaceOrientationIsLandscape
Returns a Boolean value indicating whether the user interface is currently presented in a landscape orientation.

#define UIInterfaceOrientationIsLandscape(orientation) \
   ((orientation) == UIInterfaceOrientationLandscapeLeft || \
   (orientation) == UIInterfaceOrientationLandscapeRight)