Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created October 21, 2022 13:40
Show Gist options
  • Select an option

  • Save wizard1066/ea62c06e4f7f1fd698c0d361c3ef7816 to your computer and use it in GitHub Desktop.

Select an option

Save wizard1066/ea62c06e4f7f1fd698c0d361c3ef7816 to your computer and use it in GitHub Desktop.
let longRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longTap(_:)))
view.addGestureRecognizer(longRecognizer)
@objc func longTap(_ gestureRecognize: UIGestureRecognizer) {
let p = gestureRecognize.location(in: view)
let hitResults = view.hitTest(p, options: [:])
if hitResults.count > 0 {
let result = hitResults[0].node as? NewNode
if gestureRecognize.state == .ended {
deleteNode(nodeID: result!.uid)
result?.removeFromParentNode()
}
}
}
func deleteNode(nodeID: UUID) {
let indexOf = nodes.firstIndex { (node) -> Bool in
node.uid == nodeID
}
if indexOf != nil {
// delete cell with UUID from nodes Struct Array
nodes.remove(at: indexOf!)
} else {
assert(false,"NeverHappens")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment