2012-08-23 57 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