美文网首页
SCNHitTestOption.searchMode 使用

SCNHitTestOption.searchMode 使用

作者: loongod | 来源:发表于2020-11-23 14:29 被阅读0次

一、SCNHitTestOption.searchMode 使用

            let dic:[SCNHitTestOption: Any]? = [SCNHitTestOption.boundingBoxOnly: true]
            let results = self.sceneView.hitTest(updatePosition, options: dic)
            print("count:\(results.count)")

如上代码,这样默认碰撞监测,只返回第一个碰撞到的物体,如果想把所有的碰撞结果都返回的话,需要设置

    @available(iOS 11.0, *)
    public static let searchMode: SCNHitTestOption // Determines whether the search should be exhaustive. Defaults to SCNHitTestSearchModeClosest.
// 确定搜索是否应该穷举。 默认为SCNHitTestSearchModeClosest。
@available(iOS 11.0, *)
public enum SCNHitTestSearchMode : Int {
    case closest = 0 // The closest object found.
    case all = 1 // All found objects sorted from nearest to farthest.
    case any = 2 // The first object found. This object is not necessarily the nearest.
}

但是设置了枚举之后,如下

let dic:[SCNHitTestOption: Any]? = [
  SCNHitTestOption.boundingBoxOnly: true, 
  SCNHitTestOption.searchMode: SCNHitTestSearchMode.all
]

一调用到这里的代码就会报崩溃

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__SwiftValue integerValue]: unrecognized selector sent to instance 0x281d0dbf0'

解决:这里直接使用原始值即可。

let dic:[SCNHitTestOption: Any]? = [
  SCNHitTestOption.boundingBoxOnly: true, 
  SCNHitTestOption.searchMode: 1
]

相关文章

网友评论

      本文标题:SCNHitTestOption.searchMode 使用

      本文链接:https://www.haomeiwen.com/subject/ratviktx.html