检测设备颠倒

use*_*578 2 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");
    }
Run Code Online (Sandbox Code Playgroud)

小智 7

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

UIDevice *currDevice = [UIDevice currentDevice];
[currDevice beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)

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

currDevice.orientation
Run Code Online (Sandbox Code Playgroud)

这些是返回的值:

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