5
我創建了一個SceneKit scene
到UIViewController
的遊戲。轉換UITapGestureRecognizer的SpriteKit的觸摸位置 - Swift
我實現了一個UITapGestureRecognizer
這樣的:
// TAP GESTURE
let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
sceneView.overlaySKScene?.view!.addGestureRecognizer(tapGesture)
而且handleTap
功能:
func handleTap(sender: UIGestureRecognizer) {
if sender.state == UIGestureRecognizerState.Ended {
var touchLocation = sender.locationInView(sender.view)
touchLocation = self.view.convertPoint(touchLocation, toView: self.view)
let touchedNode = sceneView.overlaySKScene?.nodeAtPoint(touchLocation)
if touchedNode == myNode {
// DO SOMETHING
}
}
}
試想一下,myNode
的立場是(x: 150.0, y: 150.0)
。 問題是touchPosition.y
與myNode
的y位置的y位置相反。
如何反轉觸摸的y位置?
謝謝!
哪裏是convertPointFromView的實施? –
這個覆蓋didMovetoView方法不是在My UIviewcontroller類中調用的。爲什麼? – Hitesh