ios - '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]
请告诉我如何解决它,谢谢:)
解决方案
您可以为节点分配一个名称,然后使用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")
}
}
}
}
推荐阅读
- java - BigInteger 有问题
- python - 使用 Pandas [Data] 打开 .dat 文件,无需 [Settings]
- python-3.x - 只比较字典中的两个值
- c# - 使用 MVVM 复制窗口关闭事件
- java - 如何防止 @FeignClient 接口中某些异常触发的 hystrix 回退?
- laravel - 如何将 spatie/laravel-feed 内容类型设置为 xml?
- javascript - 如何仅在谷歌网站上刷新嵌入的内容?
- git - 如何与其他 git 存储库共享文件夹/文件
- python - AttributeError:“Redis”对象没有属性“pubsub”
- python - Webscraping Google 新闻页面:获取 AttributeError:'NoneType' 对象没有属性 'find_all'