2012-08-23 53 views
5

我试过使用shake Gesture Recognition wrapper来检测摇动手势。 我也试着实现Geeky Lemon中建议的代码。 但我无法处理握手。有什么方法可以识别摇动手势吗?如何在Cocos2d CCLayer中添加Shake Gesture?

谢谢!

编辑1:

代码由摇晃手势识别包装演示的帮助下完成。

在init方法

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"); 
    } 
} 

回答

1

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

[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture]; 
+0

我试过了,但没有奏效。 – Marine

+0

为你尝试的 –

+0

添加一些代码请检查编辑1中的代码 – Marine

0

您对使用ShakeEnabledUIWindow而不是UIWindow。在你AppDelegate需要导入的文件,你需要为窗口创建实例,像

#import "ShakeEnabledUIWindow.h" 

然后创建实例ShakeEnabledUIWindow

@property (strong, nonatomic) ShakeEnabledUIWindow *window; 

现在,它会工作。尝试使用这些link来实现您的Shake Gesture