5

我尝试使用摇动手势识别包装器来检测摇动手势。我还尝试实现Geeky Lemon中建议的代码。但我无法处理摇晃手势。有什么方法可以识别摇晃手势吗?

谢谢!

编辑1:

代码是在摇动手势识别包装演示的帮助下完成的。

在初始化方法中

ShakeDispatcher * dispatcher = [ShakeDispatcher sharedInstance];
[dispatcher addShakeListener:self];    
[[[CCDirector sharedDirector]view] addGestureRecognizer:dispatcher];

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {  
    if ( event.subtype == UIEventSubtypeMotionShake ){      
        NSLog(@"Shake detected");   
    } 
}
4

2 回答 2

1

以正常方式创建您的手势识别器,然后像这样添加它

[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture];
于 2012-08-23T22:55:42.640 回答
0

你必须使用ShakeEnabledUIWindow而不是UIWindow. 在您AppDelegate需要导入文件并且需要为该窗口创建实例,例如

#import "ShakeEnabledUIWindow.h"

然后为ShakeEnabledUIWindow

@property (strong, nonatomic) ShakeEnabledUIWindow *window;

现在它可以工作了。试试这些链接来实现你的Shake Gesture.

于 2012-12-19T04:43:28.110 回答