Question

I succesfully implemented the shake gesture, but now I would like to limit it to activate only in one specific situation (in the options panel of my app).

  • I first created ShakeWindow class which is a subclass of UIWindow. In ShakeWindow I added - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event to register shake gesture.

  • Next I went to AppDelegate.m and edited window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; to use the new ShakeWindow instead of UIWindow.

It works great, but how do I limit it's functionality? I'm just starting Objective-C and consider myself as a novice coder overall so keep that in mind when answering, thank you!

I use Cocos2D as the framework and I don't use Interface Builder if those matter.

Was it helpful?

Solution

I might be misunderstanding, but how about...

- (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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top