【问题标题】:Need to delay touch for 3 finger swipe and not 1 finger swipe需要延迟触摸 3 指滑动而不是 1 指滑动
【发布时间】:2011-10-19 20:42:50
【问题描述】:

我正在努力将手势集成到 iPad 的绘图应用程序中。例如,我想用三指向左滑动来撤消绘图步骤。

我在阻止触摸数据进入 touchesBegan:withEvent: 时遇到问题,这会导致在执行手势时对屏幕进行绘图。

如果我使用 delayTouchesBegan 属性,我可以防止三指滑动传递此触摸数据。但是,当用户试图绘制一条向左的线时,它也会延迟绘制。这会导致线条开始远离用户开始绘制的位置。

如何确保我的应用只延迟三指滑动而不是单指滑动?

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

recognizer.numberOfTouchesRequired = 3;
recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
recognizer.delaysTouchesBegan = YES;

[self.view addGestureRecognizer:recognizer];

【问题讨论】:

    标签: ios ipad uigesturerecognizer


    【解决方案1】:

    我找到了解决此问题的方法。您可以使用传递给各种触摸方法的 UIEvent 来检测触摸次数,而不是使用手势识别器的 delayTouchesBegan 属性。然后只需将 touchBegan:withEvent:、touchesMoved:withEvent: 和 touchesEnded:withEvent: 方法中的操作限制为仅在单次触摸时执行。

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        //only process touch data if there is a single touch
        if ([[event allTouches] count] == 1) {
            //draw
        }
    }
    

    【讨论】:

      【解决方案2】:

      这是手势的一个已知问题。除了选择退出 UISwipeGestureRecognizer 并使用 touchesBegan/Ended 手动进行手势处理之外,没有其他办法。然后您可以设置一个具有较低阈值的自定义计时器。

      【讨论】:

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