은 내가 접촉을 처리 할 수있는 솔루션을 함께했다 생각합니다. UIScrollView
이 스크롤 할 수 있도록 모든 접촉을 먹기 때문에 SKScene
으로 전달해야합니다. 당신은 UIScrollView
를 서브 클래 싱하여 해당 작업을 수행 할 수 있습니다
class SpriteScrollView: UIScrollView {
var scene: SKScene?
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
scene?.touchesBegan(touches, withEvent: event)
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
scene?.touchesMoved(touches, withEvent: event)
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
scene?.touchesCancelled(touches, withEvent: event)
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
scene?.touchesEnded(touches, withEvent: event)
}
}
그런 다음 장면은 터치가 어떤 노드를 명중하고 적절하게 그 노드에 접촉을 보내는 경우 볼 필요
. 그래서
SKScene
이 추가 :이 하나의 접촉을위한 잘 오류를 처리하지 않습니다
var nodesTouched: [AnyObject] = []
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
let location = (touches.first as! UITouch).locationInNode(self)
nodesTouched = nodesAtPoint(location)
for node in nodesTouched as! [SKNode] {
node.touchesBegan(touches, withEvent: event)
}
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesMoved(touches, withEvent: event)
for node in nodesTouched as! [SKNode] {
node.touchesMoved(touches, withEvent: event)
}
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
for node in nodesTouched as! [SKNode] {
node.touchesCancelled(touches, withEvent: event)
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
for node in nodesTouched as! [SKNode] {
node.touchesEnded(touches, withEvent: event)
}
}
주, 당신의 일부를 포장하는 데 필요한 아래 if 문이 제대로이 작업을 수행하려는 경우에 주조 강제
나는이 질문이 몇 개월 된 사람에게 도움이되기를 바랍니다.
uikit 요소 (uiscrollview)를 장면에 직접 추가하고 있습니까? 아마도 최선의 방법은 아닙니다. 그냥 sknode를 슬라이드하는 것이 훨씬 쉽습니다. 그리고 네, 당신은 일종의 완화와 가속을 프로그램해야합니다. – hamobi
실제로 가속도, 속도 등을 만들어야합니다. – Maarten
이 점은 흥미로운 질문입니다. 그것을 upvoted 및 누군가에 의해 훌륭한 답변을 기대. – Maarten