摇动手势不起作用

3 iphone xcode ios4

我使用代码检测抖动和此代码在设备上工作,但当我在模拟器上使用摇动手势不起作用为什么?

我使用下面的代码来检测它

#define kAccelerationThreshold      2.2
#define kUpdateInterval         (1.0f/10.0f)

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
        if (fabsf(acceleration.x) > kAccelerationThreshold || fabsf(acceleration.y) > kAccelerationThreshold || fabsf(acceleration.z) > kAccelerationThreshold)
            ...
}
Run Code Online (Sandbox Code Playgroud)

Tom*_*ift 5

看看UIResponder的motionEnded:方法.您可以在窗口上实现motionEnded,查看或查看控制器以检测抖动,如下所示:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{
    if (event.type == UIEventSubtypeMotionShake) 
    {
        // your code here

    }
}
Run Code Online (Sandbox Code Playgroud)

在我的应用中,我需要一个应用程序范围的摇动处理程 所以我将UIWindow子类化(我的应用程序有一个窗口,就像大多数一样)并将处理程序放在该子类中.