ios - 错误 - 顶层不允许使用表达式
问题描述
我在运行此代码时遇到了一些问题,我在另一篇文章中找到了它Stack Overflow
。ARKit:如何将 UIView 添加到 ARKit 场景?
想看看它是否对我有用。但我无法弄清楚为什么会出现错误“表达式不允许在顶层”。
let text = "Hello, Stack Overflow."
let font = UIFont(name: "Arial", size: CGFloat(12))
let width = 128
let height = 128
let fontAttrs: [NSAttributedString.Key: Any] =
[NSAttributedString.Key.font: font as! UIFont]
let renderer = UIGraphicsImageRenderer(size: CGSize(width: CGFloat(width),
height: CGFloat(height)))
let image = renderer.image { context in
let color = UIColor.blue.withAlphaComponent(CGFloat(0.5))
color.setFill()
context.fill(CGRect(
origin: CGPoint(x: 0, y: 0),
size: UIScreen.main.bounds.size))
text.draw(with: (CGRect( origin: CGPoint(x: 0, y: 0), size:
UIScreen.main.bounds.size)), options: .usesLineFragmentOrigin, attributes:
fontAttrs, context: nil)
}
let plane = SCNPlane(width: CGFloat(0.1), height: CGFloat(0.1))
plane.firstMaterial?.diffuse.contents = image
let node = SCNNode(geometry: plane)
在以下代码行中发现错误“表达式不允许在顶层”:
plane.firstMaterial?.diffuse.contents = image
先感谢您。
解决方案
推荐阅读
- java - 使用括号中的 JSON 值查询 Apache Solr
- scala - 适应反应的目的是什么?
- r - 如何更改 export_summs (R) 中的 p 值星截止值
- apache-spark - 使用 Spark 和 Alluxio 管理 S3 的文件大小
- javascript - 是否可以从 HTML 网络资源刷新 Dynamics CRM 子网格?
- python - 想要找到具有最多素数除数的数字,但它一直打印最后输入的数字及其除数
- angular - http.get() 不返回 observable
- amazon-web-services - 为什么ecs-cli service up很久没有完成
- php - PHP在While循环中迭代数组的变量
- powershell - 在 PowerShell 中使用 Azure DevOps REST API 更新生成定义