ios - 为多点触控继承 UIControl 的 endTracking

标签 ios uikit multi-touch uicontrol

我通过继承 UIControl 并覆盖以下方法来创建自定义控件*:

  • - beginTrackingWithTouch:withEvent:
  • - continueTrackingWithTouch:withEvent:
  • - endTrackingWithTouch:withEvent:
  • - cancelTrackingWithEvent:

此控件将支持多点触控交互。具体来说,一个或两个手指可能会向下触摸,拖动一段时间,然后向上触摸,所有这些都是独立的。

我的问题出现在这些多点触控事件的末尾,在 endTrackingWithTouch:withEvent: 中。系统在每个多点触摸序列中仅在我的控件上调用一次此方法,并且在发生的第一次触摸时调用它。这意味着将不再跟踪可能仍在拖动的第二个触摸。

这一系列 Action 是这种现象的一个例子:

  1. 手指 A 触地。 beginTracking 被调用。
  2. 手指 A 拖来拖去。重复调用 continueTracking 来更新我的控件。
  3. 手指 B 触地。 beginTracking 被调用。
  4. 手指AB 拖来拖去。重复调用 continueTracking 来更新我的控件。
  5. 手指 B 向上移动。 endTracking 被调用。
  6. 手指 A 拖来拖去。没有调用任何方法。
  7. 手指 A 向上触摸。没有调用任何方法。

问题在于此序列中的最后三个步骤。 The documentation for UIControl表示 endTrackingWithTouch:withEvent: 的以下内容:

Sent to the control when the last touch for the given event completely ends, telling it to stop tracking.

但在我看来,在上面的第 5 步中手指 B 触摸之后,给定事件的最后一次触摸还没有完全结束。最后一次触摸是手指A!


*范围 slider ,如果您一定要问的话。 但是已经有很多开源范围 slider ,您说。是的,没错,但是这个将支持多点触控和自动布局。

最佳答案

我在使用多点触控的自定义控件中遇到了同样的问题。
因为 UIControl 是继承自 UIResponderUIView 的子类,所以可以随意使用:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

方法。

这些方法在 UIControl 子类中运行良好。

关于ios - 为多点触控继承 UIControl 的 endTracking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26820827/

相关文章:

iOS UIPageControl 替换状态栏

java - 正确处理多点触摸事件android

ios - 导航栏标题 - 更改字体而不更改大小

ios - NSSearchPathForDirectoriesInDomains 在模拟器上工作但不在设备上工作

android - Processing 可以处理多点触控吗?

iphone - 多点触控在 cocos2d 中不起作用

ios - 使用 Swift 3.0 实时画线

ios - 循环 ImageView 动画 iOS

ios - 如何在 iOS 6 上的 Safari 中获取此栏?

iphone - 当涉及高度动画的用户界面时,openGL ES 是否比 Core Animation 和 UIKit 具有更好的性能?