ios - 仅当触摸类型为手指时,如何将触摸事件传递给其他 View ?

标签 ios swift touches

我在我的 View 上有一个 subview ,我希望这个 subview 只识别铅笔触摸类型。每次触摸类型是手指时,我都希望它能被父 View 识别。目前我正在使用下面显示的功能。这里的问题是 UIEvent 没有触摸,因此无法检查它是手指还是铅笔触摸。

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    return false
}

最佳答案

更新

一个选项是在底部 View 中禁用用户交互,并在顶部 View 中实现:

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent)
func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent)
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent)

在这些函数中,你可以用touches.first?.type检查类型,你可以用touches.first?.view检查 View ,如果它们满足您的条件,您可以在底部 View 上调用 touchesBegan/Moved/Ended

之前说了什么:

使用这三种方法:

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent)
func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent)
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent)

您可以使用 touches.first?.type 检查它们的类型,您可以使用 touches.first?.view 检查 View 。

您可以通过在下面的 View 上调用 touchesBegan/Moved/Ended 来转发触摸。

关于ios - 仅当触摸类型为手指时,如何将触摸事件传递给其他 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57279637/

相关文章:

ios5 - TouchesEnded 在 iOS5 中不起作用,在 iOS4 中工作正常

ios - 在 UITextField 上禁用触摸但不是所有用户交互

ios - 从 iOS 应用程序 (Swift) 自动打开 .ibooks 文件

ios - SpriteKit SKScene 缺少 touchesEnded

ios - 如何确保在同一个后台线程上运行一些代码?

ios - 从另一个 pickerView 选择项目时隐藏 pickerView 的行

ios - 由于错误 :,JSON 无法序列化

swift - 无法调用非函数类型的值 'CIImage?'

ios - URL WebView Swift Xcode 7

ios - 在启动时显示模式登录 - 通过 UITableView