@objc func tapped(sender: UITapGestureRecognizer) {
let sceneView = sender.view as! ARSCNView
let tapLocation = sender.location(in: sceneView)
let hitTest = sceneView.hitTest(tapLocation, types: .existingPlaneUsingExtent)
if !hitTest.isEmpty {
addItem(hitTestResult: hitTest.first!)
hideTip()
}
}
它是在点击平面时添加节点的,但是现在我想检测节点何时被点击,我使用了以下代码:
let sceneView = sender.view as! ARSCNView
let tapLocation = sender.location(in: sceneView)
let hitTouchTest = sceneView.hitTest(tapLocation)
if !hitTouchTest.isEmpty {
let results = hitTouchTest.first!
let node = results.node
}
它输入if,但节点的名称总是nil,当我创建节点并将其添加到平面时,我给它一个名称。。。如何检测节点已被点击?