Cannot get locationInView: for this type of NSTouch assertion error when trying to retrieve location

南笙酒味 提交于 2019-12-25 01:29:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!