Created
October 21, 2022 13:28
-
-
Save wizard1066/05992a1d4c3d818b023b116b684cbf7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:))) | |
| view.addGestureRecognizer(panRecognizer) | |
| @objc func handlePan(_ gestureRecognize: UIPanGestureRecognizer) { | |
| let p = gestureRecognize.location(in: view) | |
| let hitResults = view.hitTest(p, options: [:]) | |
| if hitResults.count > 0 { | |
| let result = hitResults[hitResults.count - 1].node as? NewNode | |
| let newPosition = p.scnVector3Value(view: view, depth: Float(result!.position.z)) | |
| reassignNode(newNode: result!, newPosition: newPosition) | |
| } | |
| } | |
| func reassignNode(newNode: NewNode, newPosition:SCNVector3) { | |
| let indexOf = nodes.firstIndex { (node) -> Bool in | |
| node.uid == newNode.uid | |
| } | |
| if indexOf != nil { | |
| newNode.position = newPosition | |
| nodes[indexOf!] = newNode | |
| } else { | |
| assert(false,"NeverHappens") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment