繁体   English   中英

如何将iPhone摇动手势检测限制在特定情况下?

[英]How to limit iPhone shake gesture detection to specific situation?

我成功实现了摇动手势,但是现在我想限制它只能在一种特定情况下(在我的应用程序的选项面板中)激活。

  • 我首先创建了ShakeWindow类,它是UIWindow的子类。 在ShakeWindow中,我添加了- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event以注册摇动手势。

  • 接下来,我转到AppDelegate.m,然后编辑window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 使用新的ShakeWindow而不是UIWindow。

它很好用,但是我如何限制它的功能呢? 我只是开始使用Objective-C,并把自己当作一个新手,所以在回答时请记住这一点,谢谢!

我使用Cocos2D作为框架,如果那很重要的话,我不会使用Interface Builder。

我可能会误会,但是...

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

    if (/* conditions where my app responds to shake */) {
        // respond to shake
    }
    // otherwise, it's like it never happened
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM