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");
}
}
以正常方式创建手势识别器,然后像这样添加它
[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture];
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.