[英]How to add button and label to the scene
我是Scenekit和ARKit的新手,我想在UIView中添加按鈕和標簽到Scenekit的場景中。 我通過命中測試獲得世界坐標以放置視圖,但是SCNNode沒有addSubView
方法來添加視圖。
我想實現以下輸出:
我試圖實現這一目標:
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)
}
錯誤:
請提出我可以完成的方法。
要將UIView
對象添加到場景節點,可以將其分配給節點的幾何圖形材質漫反射內容。 它會被添加到節點並在您移動設備時保持其位置:
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.