我有一个绘图应用程序,它的画布比手机屏幕大小。我想实现两个手指滚动,一个手指作画。到目前为止,我可以使滚动工作正常,但当涉及到绘制时,线开始,然后绘制的视图失去了对触摸的控制,从而只绘制了线的第一部分。我认为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
}发布于 2017-10-22 10:04:47
您将需要一个连接到您的ScrollerView的长按手势识别器,设置为最小持续时间0秒,还可以识别only 1 Touch和Cancel touches in view选项激活。
您可以在Interface Builder上的Attributes Inspector下找到所有这些选项。
请稍微调整一下容差设置以微调结果。
https://stackoverflow.com/questions/46869483
复制相似问题