【问题标题】:How Can I add Shake Gesture in Cocos2d CCLayer?如何在 Cocos2d CCLayer 中添加摇动手势?
【发布时间】:2012-08-23 13:02:52
【问题描述】:

我尝试使用shake Gesture Recognition wrapper 来检测摇晃手势。 我还尝试实现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");   
    } 
}

【问题讨论】:

    标签: iphone cocos2d-iphone gesture shake


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      #import "ShakeEnabledUIWindow.h"
      

      然后为ShakeEnabledUIWindow创建实例

      @property (strong, nonatomic) ShakeEnabledUIWindow *window;
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多