swift - 缺少 SCNText 的 textSize 属性

标签 swift arkit arscnview scntext

我想在 ARSCNView 中的 SCNText 周围添加一个 SCNPlane。因此,我需要使用 SCNText 创建的文本的 textSize,例如:

enter image description here

正如您从图像中看到的那样,有一个错误表明

SCNText has no member 'textSize'

但我可以在苹果网站上看到关于 SCNText 的相关文档和 textSize .

有人知道问题出在哪里吗?我该如何访问 textSize 属性?

我使用的是 xCode 10.0 beta 4、swift 4.2、macOS Mojave 10.14 Beta。

最佳答案

textSize 属性仅在 macOS 10.8+ 上可用,这就是您看不到它的原因(当然假设您正在为 IOS 构建)。我的意思是,如果您正在构建 MacOS 应用程序,那么该变量是可访问的。而如果您正在为 IOS 构建,则不是。

如果你想获得 SCNText 的大小,你可以使用它的 boundingBox 属性来获得它的宽度和高度,例如:

 //1. Get The Bounding Box Of The Text Node
 let boundingBox = textNode.boundingBox

 //2. Get The Width & Height Of Our Node
 let width = boundingBox.max.x - boundingBox.min.x
 let height = boundingBox.max.y - boundingBox.min.y

如果你只想设置字体大小,你可以这样做:

 //1. Create An SCNNode With An SCNText Geometry
 let textNode = SCNNode()
 let textGeometry = SCNText(string: "StackOverflow", extrusionDepth: 1)
 textGeometry.font = UIFont(name: "Skia-Regular_Black", size: 20)

当然要记住,当您在 ARKit 中指定字体大小时,这是以米为单位的。

希望对你有帮助

关于swift - 缺少 SCNText 的 textSize 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51951345/

相关文章:

ios - DateComponentsFormatter 显示前导零

swift - ARKIT 无法在渲染方法中缩放或旋转

swift - SCNParticleSystem 未在 touchesbegan 上添加到 SCNNode

ios - 多层 scn 文件需要时间来渲染 arkit

Swift ARKit 如何完全杀死 ARSession?

ios - 快速将 backButton 从默认 UINavigationbar 移动到 customNavigationbar

swift - CloudKit 谓词 : Search multiple reference fields with predicate of CKQuery

ios - 在 7.1 设备 swift xcode6 beta 3 上调试时出错

ios - ARKit - 最初将对象以相机的特定航向/角度放置在 ARSKView 中

objective-c - 使用 "SCNView"而不是 "ARSCNView"– 当不支持时