如何将标签/ UIView固定到ARKit中的节点

时间:2018-06-23 03:04:41

标签: ios iphone swift uiview arkit

我想让UILabel停留在ARKit的节点上,类似于iOS 12的Measure应用中的尺寸标签。 我尝试将标签添加为平面节点并使用广告牌约束,但是随着您移开,文本会变小,这是不理想的。 在WWDC,他们将其称为“屏幕空间”,但没有说明如何实现。

提前谢谢! enter image description here

2 个答案:

答案 0 :(得分:3)

我想出了以下解决方案来使其正常工作。

首先,我创建UILabel并将其添加为子视图。接下来,我将要跟随的节点的位置转换为const color = 'Red' switch(color) { case 'Red': //do something case 'Green': //something else } 中的屏幕坐标。现在,标签正确地跟随节点并保持固定比例。但是,标签与屏幕保持水平,这看起来很奇怪。为了使其与世界保持水平,我根据ARCamera的偏航(z旋转)旋转标签。

renderer(_: updateAtTime:)

答案 1 :(得分:0)

尝试使用SCNText几何,几个月前我使用了以下代码:

    var txtNote    = SCNText()
    txtNote.string = "Hello AR word!"
    txtNote.font   = UIFont.systemFont(ofSize: 2)
    txtNote.extrusionDepth = 1.0
    txtNote.containerFrame = CGRect(x: 2.5, y: 0, width: 16, height: 10)
    txtNote.isWrapped      = true
    txtNote.alignmentMode  = kCAAlignmentLeft
    txtNote.materials.first?.diffuse.contents = UIColor.black.cgColor

    var txtNode = SCNNode(geometry: txtNote)