문제

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.

도움이 되었습니까?

해결책

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top