【发布时间】:2018-03-06 23:42:25
【问题描述】:
我在 SCNode 命中检测方面遇到了一些问题。我需要检测在具有 SCNNode 的场景中触摸了哪个对象,我已经实现了这段代码,但是当我触摸对象时它似乎崩溃了,但当我触摸场景视图的其余部分时它工作得很好。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first as! UITouch
if(touch.view == self.sceneView){
print("touch working")
let viewTouchLocation:CGPoint = touch.location(in: sceneView)
guard let result = sceneView.hitTest(viewTouchLocation, options: nil).first else {
return
}
if (bottleNode?.contains(result.node))! { //bottleNode is declared as SCNNode? and it's crashing here
print("match")
}
}
}
【问题讨论】:
标签: swift scenekit arkit scnnode