1
我有一個畫布大於手機屏幕大小的繪圖應用程序。我想實現用兩個手指滾動並用一個手指畫圖。到目前爲止,我可以使滾動工作很好,但是當涉及到繪圖時,該行開始,然後視圖中的圖形失去對觸摸的控制,從而只繪製第一部分。我認爲scrollview控制了。點可以畫得很好。使UIScrollView放棄UITouch
這是我的子類的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
}
我確實有**取消接觸在視圖選項活動**,但對不起,你是什麼意思只識別一次觸摸?我仍然希望滾動視圖能夠識別兩個觸摸,以及將一次觸摸傳遞給下一個響應者,這將是我的畫布。我會嘗試長按手勢識別器,但我需要經常更新畫布以模擬繪圖,並且我希望使用touchesmoved方法,因爲我不知道如何在識別器的選擇器中完成該操作,謝謝。答案順便會嘗試! –
對不起,也許我不清楚。 您應該依靠GestureRecognizer捕捉觸摸並採取相應的行動,從而有效地取消觸摸底層視圖。 我成功使用此設置捕捉繪圖和手勢。 從我所瞭解的情況來看,UIScrollView無法有效地管理平移/拖拽手勢,將它們傳遞給它所包含的視圖。 –
你能使它工作嗎? –