繁体   English   中英

如何在ARkit ios的sceneVIew节点内添加textview

[英]How to add textview inside a node of sceneVIew in ARkit ios

我是 AR 开发的新手,目前正在使用一个基于视频通话的应用程序使用 AR 功能,因此需要在 sceneview 的节点中添加 UITextview

我尝试使用以下代码:

  let scanInfo = UITextView(frame:CGRect(x: location.x, y: location.y, width: 100, height: 80))

    scanInfo.textAlignment = .left
    scanInfo.textColor = UIColor.white
    scanInfo.text = "SCAN A SURFACE"

  sceneView.addSubview(scanInfo)

如果有人对此有一些想法,请告诉我

嘿伙计们我得到了我自己的问题的解决方案希望这有帮助。

添加一个平面节点并在其中添加 SCNtext 作为平面节点的子节点

sceneView.automaticallyUpdatesLighting = true
sceneView.autoenablesDefaultLighting = true
   
guard let anchor = self.makeAnchor(at: location) else {return}
   
let plane = SCNPlane(width: 50, height: 50)
plane.materials.first?.diffuse.contents = UIColor.gray
    
let planeNode = SCNNode(geometry: plane)
    
planeNode.scale = SCNVector3(0.0015, 0.0015, 0.0015)
planeNode.position = SCNVector3(anchor.transform.columns.3.x ,anchor.transform.columns.3.y,anchor.transform.columns.3.z)
    
let yawn = sceneView.session.currentFrame?.camera.eulerAngles.y
    
planeNode.eulerAngles.y = (yawn ?? 0) + .pi * 2
planeNode.eulerAngles.x =(sceneView.session.currentFrame?.camera.eulerAngles.x ?? 0)
lastnode = planeNode
sceneView.scene.rootNode.addChildNode(planeNode)


  let text = SCNText(string: textSrting, extrusionDepth: 1)
    let material = SCNMaterial()
    material.diffuse.contents = UIColor.white
    material.multiply.intensity = 0.8
    material.specular.contents = UIColor.red
    material.isDoubleSided = true

    material.locksAmbientWithDiffuse = true

    let (min, max) = lastnode!.boundingBox
    let width = CGFloat(max.x - min.x)
    let height = CGFloat(max.y - min.y)
    text.containerFrame = CGRect(x: CGFloat(min.x + 2), y: CGFloat(min.y - 2), width: (width - 3) , height: (height + 2))
    text.truncationMode = CATextLayerTruncationMode.middle.rawValue
    text.isWrapped = true
    text.alignmentMode = CATextLayerAlignmentMode.left.rawValue
    text.truncationMode = CATextLayerTruncationMode.middle.rawValue

    text.font = UIFont(name: "Proxima-nova", size: 3)
    text.materials = [material]
    
    
    let textNode = SCNNode(geometry: text)

    lastnode?.addChildNode(textNode)
   

暂无
暂无

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

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