【问题标题】:UIView touchesCancelled Not CalledUIView touchesCancelled 未调用
【发布时间】:2023-04-06 12:44:01
【问题描述】:

我有一个子类 UIView 没有收到 touchesCancelled。如果触摸下来并拖到屏幕外(或应调用touchesCancelled 的任何其他实例),则调用touchesEnded 而不是touchesCancelled。它永远不会被调用!

我明白了:

self.clipsToBounds = true
self.isExclusiveTouch = true
self.isMultipleTouchEnabled = false

其他同级视图似乎会调用它们的touchesCancelled。我也没有附加手势识别器。

【问题讨论】:

  • 请显示实际代码,而不是带有一些属性的小片段,并解释如何执行“触摸下来并拖动到屏幕外”以及您的期望。您显示的代码中甚至没有任何touchesCancelled!没办法问这个问题。请证明一个 MCVE。

标签: ios swift xcode uiview touch


【解决方案1】:

来自 Apple 文档 https://developer.apple.com/documentation/uikit/uiresponder/1621116-touchescancelled ...

UIKit 在收到需要取消触摸序列的系统中断时调用此方法。中断是导致应用程序变为非活动状态或导致处理触摸事件的视图从其窗口中移除的任何事情。

所以touchesCancelled不会在触摸移动/拖动到视图之外时被调用。

【讨论】:

  • 抱歉,我必须更正 OP,我的意思是“在屏幕外”。在其他视图中也会调用 touchesCancelled 的任何其他事件。
  • 这仍然不是“系统中断”——你得到touchesEnded是设计的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-19
  • 1970-01-01
  • 2017-10-03
  • 2010-12-07
  • 1970-01-01
  • 2014-09-16
相关资源
最近更新 更多