我在我的 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/