简体   繁体   English

如何在场景中添加按钮和标签

[英]How to add button and label to the scene

I am new in Scenekit and ARKit, I wanted to add button and label inside UIView to the scenekit's scene. 我是Scenekit和ARKit的新手,我想在UIView中添加按钮和标签到Scenekit的场景中。 I am getting the world coordinates by the hit test to place the view but SCNNode don't have addSubView Method to add view. 我通过命中测试获得世界坐标以放置视图,但是SCNNode没有addSubView方法来添加视图。

I want to achieve following output : 我想实现以下输出:

在此处输入图片说明

My attempts to achieve this : 我试图实现这一目标:

func addHotspot(result : SCNHitTestResult, parentNode : SCNNode? = nil) {
    let view = UIView()
    view.backgroundColor = .red

    let material = SCNMaterial()
    material.diffuse.contents = view

    let plane = SCNPlane(width: 100, height: 100)
    plane.materials = [material]

    let node = SCNNode()
    node.geometry = plane

    node.position = result.worldCoordinates
    parentNode?.addChildNode(node)
}

error : 错误:

在此处输入图片说明

Please suggest the way I can complete it. 请提出我可以完成的方法。

To add a UIView object to a scene node, you can assign it to the node's geometry material diffuse content. 要将UIView对象添加到场景节点,可以将其分配给节点的几何图形材质漫反射内容。 It will be added to the node and will maintain its position as you move your device around: 它会被添加到节点并在您移动设备时保持其位置:

DispatchQueue.main.async {
  let view: UIView = getView() // this is your UIView instance that you want to add to the node

  let material = SCNMaterial()
  material.diffuse.contents = view

  node.geometry.materials = [material]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM