5

I've tried using shake Gesture Recognition wrapper to detect the shake gesture. I've also tried to implement the code suggested in the Geeky Lemon. But I am unable to handle the shake gesture. Is there any way to get the shake gesture recognized?

Thank you!

EDIT 1:

The code is done by the help of the shake Gesture Recognition wrapper demo.

in the init method

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");   
    } 
}
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
Marine
  • 1,097
  • 7
  • 19

2 Answers2

1

Create your gesture recogniser the normal way and then add it like so

[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture];
Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
0

You've to use ShakeEnabledUIWindow instead of UIWindow. In your AppDelegate you need to import the file and you need to create instance for that window, like

#import "ShakeEnabledUIWindow.h"

Then create instance for ShakeEnabledUIWindow

@property (strong, nonatomic) ShakeEnabledUIWindow *window;

Now it'll work. Try these link for implementing your Shake Gesture.

arthankamal
  • 6,341
  • 4
  • 36
  • 51