【问题标题】:Detecting a double tap gesture only once仅检测一次双击手势
【发布时间】:2014-10-04 17:33:58
【问题描述】:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *aTouch in touches) {
        if (aTouch.tapCount >= 2) {
            // The view responds to the tap
        }
    }
}

我正在使用上面的代码来检测双击手势;但是,如何将代码设置为只发生一次?

换句话说,当您点击一次时,角色就会跳跃。当您快速连续点击两次时,角色将进行二段跳。但是,如何设置点按,以使角色不会在没有最初点按一次的情况下连续双跳并在单视图中跳得更高?

【问题讨论】:

    标签: ios objective-c sprite-kit xcode6


    【解决方案1】:

    实现这一点的一个非常简单的方法是声明一个全局bool 变量并在检测到双击后设置它的值!

    类似这样的:

    @interface MyViewController()
    {
        bool isTapped;
    }
    @end
    
    @implementation MyViewController
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        for (UITouch *aTouch in touches) {
            if (aTouch.tapCount >= 2) {
                if(!isTapped) {
                    // The view responds to the tap
                    isTapped = YES;
                }
            }
        }
    }
    @end
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      不确定这是否有帮助,也只需要一个标志并相应地设置它是或否:-

      UILongPressGestureRecognizer *tapRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
      tapRecognizer.delegate = self;
      tapRecognizer.minimumPressDuration = //Up to you;
      [self.someView addGestureRecognizer:tapRecognizer];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多