文字换行不适用于" SCNText"节点

时间:2017-10-06 13:20:48

标签: ios iphone scenekit augmented-reality arkit

我能够在AR环境中显示SCNText但是当我尝试将文本包装在固定宽度和高度的容器中时,而是将其显示在多行中,它会重叠。

let text = SCNText(string: ktext, extrusionDepth: 0.0)
text.name = "text"
text.firstMaterial?.diffuse.contents = color
text.font = UIFont(name: fontName, size: size)
text.truncationMode = kCAAlignmentCenter
text.isWrapped = true
text.truncationMode = kCATruncationMiddle
text.containerFrame.size = CGSize(width: 3, height: 1)

enter image description here

1 个答案:

答案 0 :(得分:0)

如果在SCNText对象上使用“正常”字体大小并包含框架,然后在包含该字体的节点上设置缩放比例,则所有内容都会按预期进行换行。像这样:

let extrudedText = SCNText(string: definition.text, extrusionDepth: 0.1)
extrudedText.font = UIFont(name: definition.fontname, size: 0.2)!
...
extrudedText.font = UIFont(name: definition.fontname, size: 20)! 
extrudedText.containerFrame = CGRect(origin: .zero, size: CGSize(width: 100.0, height: 500.0))
...
scale = SCNVector3Make(0.01, 0.01, 0.01)