问题
I'm trying to retrieve the mouse location after a user clicks on a specific SCNNode. I eventually want to perform a hit test to determine which SCNNode was clicked. I have the following code but once I run the project I get an assertion error stating: "Cannot get locationInView: for this type of NSTouch". Any help would be appreciated.
override func touchesBegan(with event: NSEvent) {
let touch = event.touches(for: self.view)
if #available(OSX 10.12.2, *) {
let location = touch.first?.location(in: self.view)
let hitResults = sceneView.hitTest(location!, options: nil)
} else {
// Fallback on earlier versions
}
}
回答1:
-locationInView: will only work for touches of type NSTouchTypeDirect. If you have a Mac with a Touch Bar, pressing it will lead to an event with a touch of type NSTouchTypeIndirect which has no location on the screen.
来源:https://stackoverflow.com/questions/48737779/cannot-get-locationinview-for-this-type-of-nstouch-assertion-error-when-trying