Swift SCNNode子类hittest总是返回SCNNode *而不是* subclass
发布时间:2020-12-14 04:38:22 所属栏目:百科 来源:网络整理
导读:我有一个SCNNode的子类“ExSCNNode”来向SCNNode添加更多属性和行为. class ExSCNNode : SCNNode {...} 我比使用ExSCNNode构建一个场景. let testnode = ExSCNNode() 当测试场景时: // check what nodes are tappedlet p = gestureRecognize.location(in: s
我有一个SCNNode的子类“ExSCNNode”来向SCNNode添加更多属性和行为.
class ExSCNNode : SCNNode { ... } 我比使用ExSCNNode构建一个场景. let testnode = ExSCNNode() 当测试场景时: // check what nodes are tapped let p = gestureRecognize.location(in: scnView) let hitResults = scnView.hitTest(p,options: [:]) // check that we clicked on at least one object if hitResults.count > 0 { for hit in hitResults { let hitnode = hit.node ... hitnode是SCNNode而不是ExSCNNode. 如何访问子类而不是SCNNode类? 解决方法
只需将对象强制转换为子类:
// check what nodes are tapped let p = gestureRecognize.location(in: scnView) let hitResults = scnView.hitTest(p,options: [:]) for hit in hitResults { if let hitnode = hit.node as? ExSCNNode { … } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |