【问题标题】:'hitTest()' was Depecrated in iOS 14.0'hotTest()' 在 iOS 14.0 中已弃用
【发布时间】:2021-01-23 05:42:30
【问题描述】:

我是新手,目前正在构建一个与 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]

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

【问题讨论】:

标签: ios swift raycasting hittest arscnview


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    是的,使用raycastQuery(from:allowing:alignment:)

    按照 Xcode 的建议:

    ...
    let location = gesture.location(in: sceneView)
    guard let query = sceneView.raycastQuery(from: location, allowing: .existingPlaneInfinite, alignment: .any) else {
       return
    }
            
    let results = sceneView.session.raycast(query)
    guard let hitTestResult = results.first else {
       print("No surface found")
       return
    }
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      相关资源
      最近更新 更多