Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将iPhone抖动手势检测限制在特定情况下?_Iphone_Objective C_Ios_Accelerometer_Shake - Fatal编程技术网

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

如何将iPhone抖动手势检测限制在特定情况下?,iphone,objective-c,ios,accelerometer,shake,Iphone,Objective C,Ios,Accelerometer,Shake,我成功地实现了摇晃手势,但现在我想限制它仅在一种特定情况下激活(在我的应用程序的选项面板中) 我首先创建了ShakeWindow类,它是UIWindow的一个子类。在ShakeWindow中,我添加了-(void)motionEnded:(UIEventSubtype)motion with event:(UIEvent*)event,以注册抖动手势 接下来,我转到AppDelegate.m并编辑了window=[[UIWindow alloc]initWithFrame:[UIScreen

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

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

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

它工作得很好,但我如何限制它的功能?我刚刚开始Objy-C并把自己当成一个新手编码器,所以在回答时请记住这一点,谢谢!p>
我使用Cocos2D作为框架,如果有关系的话,我不使用界面生成器。

我可能会误解,但是

- (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
}

我可能误解了,但是

- (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
}

我必须说,有时候我会让最简单的事情看起来比实际情况更难。谢谢。我必须说,有时候我会让最简单的事情看起来比实际情况更难。非常感谢。