gpt4 book ai didi

ios - 让 UIScrollView 放弃 UITouch

转载 作者:行者123 更新时间:2023-11-28 08:00:12 27 4
gpt4 key购买 nike

我有一个 Canvas 比手机屏幕大的绘图应用程序。我想实现用两根手指滚动并用一根手指绘图。到目前为止,我可以使滚动工作得很好,但是当涉及到绘图时,线条开始,然后绘图所在的 View 失去了对触摸的控制,因此只绘制了线条的第一部分。我认为 ScrollView 夺回了控制权。点可以画得很好。

这是我的子类 UIScrollView

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touches = event?.touches(for: self) else { return }
if touches.count < 2 {
self.next?.touchesBegan(touches, with: event)
} else {
super.touchesBegan(touches, with: event)
}
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touches = event?.touches(for: self) else { return }
if touches.count < 2 {
self.next?.touchesEnded(touches, with: event)
} else {
super.touchesEnded(touches, with: event)
}
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touches = event?.touches(for: self) else { return }
if touches.count < 2 {
self.next?.touchesMoved(touches, with: event)
} else {
super.touchesMoved(touches, with: event)
}
}

override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touches = event?.touches(for: self) else { return }
if touches.count < 2 {
self.next?.touchesCancelled(touches, with: event)
} else {
super.touchesCancelled(touches, with: event)
}
}

override func touchesShouldCancel(in view: UIView) -> Bool {
if (type(of: view)) == UIScrollView.self {
return true
}
return false
}

最佳答案

您需要将长按手势识别器连接到您的 ScrollerView,设置为最短持续时间 0 秒,同时识别仅 1 次触摸取消触摸查看选项处于事件状态。

您可以在 Interface Builder 的属性检查器下找到所有这些选项。

请稍微调整容差设置以微调结果。

关于ios - 让 UIScrollView 放弃 UITouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46869483/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com