检测设备颠倒

时间:2011-09-28 23:53:06

标签: iphone uiaccelerometer

检测设备的正确值是什么?

我有以下内容,它开始检测用户何时在背面标题设备。

我使用以下值

float xx = -[acceleration x];
    float yy = [acceleration y];
    float angle = atan2(yy, xx);

    if(angle >= 0.75 && angle <= 2.25)
    {
        NSLog(@"Upside down");
    }

3 个答案:

答案 0 :(得分:7)

使用以下方式开始侦听方向事件:

UIDevice *currDevice = [UIDevice currentDevice];
[currDevice beginGeneratingDeviceOrientationNotifications];

然后,使用以下方式获取方向:

currDevice.orientation

这些是返回的值:

{'1':'肖像',                                  '2':'PortraitUpsideDown',                                  '3':'LandscapeLeft',                                  '4':'LandscapeRight',                                  '5':'FaceUp',                                  '6':'FaceDown'}

答案 1 :(得分:1)

UIDevice Class Reference

请参阅“获取设备方向”部分。

答案 2 :(得分:0)

这是我在iOS上实现设备方向处理的方法(带代码),如果您愿意,可以使用它:

How to handle UIDeviceOrientation for manage views layouts

相关问题