【问题标题】:touchesMoved called without touchesBegantouchesMoved 在没有 touchesBegan 的情况下调用
【发布时间】:2012-03-13 00:00:47
【问题描述】:

我在一个容器中有许多自定义 UIView,我会在用户移动它们后对其进行动画处理。为了跟踪他们的运动,我使用touchesBegan: 获取当前位置,并使用touchesMoved: 更新位置。

有时,特别是如果我最近移动了一个视图(并且它可能仍在动画回其原始位置),如果我开始拖动另一个视图,touchesBegan: 选择器将不会被调用,但touchesMoved:touchesEnded: 将会。 touchesMoved:touchesEnded: 不首先在视图上调用,如何调用 touchesBegan:

【问题讨论】:

    标签: iphone objective-c ios touchesbegan touchesmoved


    【解决方案1】:

    我发现我的应用存在类似问题。当我为另一个视图设置动画时,如果我快速触摸第一个视图并开始滑动,则不会发生 touchesBegan 事件,但一旦第一个视图消失,我就会开始获取 touchesMoved。

    根据这个答案app starts ignores user interaction events when i call animateWithDuration:delay:options:animations:completion:,用户交互事件在制作动画时会被忽略,我认为这与我们所看到的一致。尝试使用UIViewAnimationOptionAllowUserInteraction 选项或userInteractionEnabled 属性;这应该允许事件按您的要求通过。

    【讨论】:

      【解决方案2】:

      可能值得重新阅读Apple docs。我不确定touchesBegan 是否保证会被调用。

      我猜你正在记录 touchesBegan 等事件。也许正确的事件正在触发,但日志消息显示“无序”?

      【讨论】:

      • 我以为我记得读过 touchesBegan 肯定会被调用,但我想我记错了。我正在记录每个触摸事件,当错误发生时它从不记录 touchesBegan。如果找不到更好的解决方案,我会保留一个标志来告知何时调用 touchesBegan,并且仅在设置该标志时执行 touchesMoved 和 touchesEnded 操作。
      猜你喜欢
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多