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
}
볼 수있는 터치 옵션 ** 활성화 ** 미안하지만 1 터치 만 인식하면 무엇을 의미합니까? 나는 여전히 스크롤 뷰가 2 개의 터치를 인식 할 수 있도록 원 터치를 내 캔버스가 될 다음 응답자로 전달합니다. 긴 프레스 제스처 인식기를 사용해 보겠습니다. 그러나 드로잉을 시뮬레이션하기 위해 캔버스를 자주 업데이트해야하며, 인식기의 선택기에서이를 수행하는 방법을 잘 모르기 때문에 touchesmoved 메서드를 사용하고 싶습니다. 대답 btw 시도합니다! –
죄송합니다, 아마도 나는 명확하지 않았습니다. GestureRecognizer를 사용하여 터치를 캡처하고 이에 따라 행동해야하므로 기본보기의 터치를 효과적으로 취소 할 수 있습니다. 이 설정을 사용하여 이전에 그림 및 제스처를 캡처했습니다. UIScrollView는 팬/드래그 동작을 효율적으로 관리 할 수 없어 포함 된보기에이를 전달합니다. –
작동시킬 수 있었습니까? –