首页 > 解决方案 > 'hitTest()' 在 iOS 14.0 中被弃用

问题描述

我是新手,目前正在构建一个与 AR 相关的应用程序,在旧版本上我说过这个

let results = self.hitTest(screenPosition, types: [.featurePoint])

现在我遇到了一个问题,即在 iOS 14.0 中不推荐使用 hitTest

hitTest(_:types:)' was deprecated in iOS 14.0: Use [ARSCNView raycastQueryFromPoint:allowingTarget:alignment]

请告诉我如何解决它,谢谢:)

标签: iosswiftraycastinghittestarscnview

解决方案


您可以为节点分配一个名称,然后使用hitTest(point:, options:[SCNHitTestOption : Any]?)in touchesBegan。下面是我使用的代码:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let touch = touches.first {
        let touchLocation = touch.location(in: sceneView)
        let results = sceneView.hitTest(touchLocation, options: [SCNHitTestOption.searchMode : 1])
        
        for result in results.filter({$0.node.name != nil}) {
            if result.node.name == "planeNode" {
                print("touched the planeNode")
            }
        }
    }
}

推荐阅读