gpt4 book ai didi

swift - 无法获取 locationInView : for this type of NSTouch assertion error when trying to retrieve location

转载 作者:行者123 更新时间:2023-11-30 11:46:49 25 4
gpt4 key购买 nike

我试图在用户单击特定的 SCNNode 后检索鼠标位置。我最终想要执行 HitTest 来确定单击了哪个 SCNNode。我有以下代码,但是一旦运行该项目,我就会收到一个断言错误,指出:“无法获取 locationInView:对于这种类型的 NSTouch”。任何帮助将不胜感激。

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
}
}

最佳答案

-locationInView:仅适用于 type 的触摸NSTouchTypeDirect 。如果您的 Mac 带有 Touch Bar,则按下它会导致出现类型为 NSTouchTypeIndirect 的触摸事件。它在屏幕上没有位置。

关于swift - 无法获取 locationInView : for this type of NSTouch assertion error when trying to retrieve location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48737779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com