0

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

  • 我首先创建了 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。

4

1 回答 1

4

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

- (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
}
于 2012-03-25T19:30:37.657 回答