ios - 我如何在 ARkit 场景 iOS 中添加具有文本的 2dView

标签 ios swift scenekit arkit

我如何在 ARkit 场景 iOS 中添加一个具有文本的 2dView。我如何在节点顶部添加该 View ,当我们旋转节点时该节点不会旋转。 enter image description here

最佳答案

您可以添加一个 SCNPlane 并使用 SCNLookAtConstraint以便飞机始终注视着相机。

您可以创建自定义 Material 并将其设置为 material properties到:

  • A color (UIColor or CGColor), specifying a constant color across the material’s surface A number (

  • An image (UIImage or CGImage), specifying a texture to be mapped across the material’s surface

  • A Core Animation layer (CALayer)
  • A texture (SKTexture, MDLTexture, MTLTexture, or GLKTextureInfo)
  • A SpriteKit scene (SKScene)

您也可以使用 CoreAnimation 或 SpriteKit 显示动画内容,但是

SceneKit cannot use a layer that is already being displayed elsewhere (for example, the backing layer of a UIView object)


这是一个使用 SpriteKit 的例子:

  1. 创建您的 SpriteKit 场景:

例如:

let skScene = SKScene(size: CGSize(width: 200, height: 200))
skScene.backgroundColor = UIColor.clear

let rectangle = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 200, height: 200), cornerRadius: 10)
rectangle.fillColor = #colorLiteral(red: 0.807843148708344, green: 0.0274509806185961, blue: 0.333333343267441, alpha: 1.0)
rectangle.strokeColor = #colorLiteral(red: 0.439215689897537, green: 0.0117647061124444, blue: 0.192156866192818, alpha: 1.0)
rectangle.lineWidth = 5
rectangle.alpha = 0.4
let labelNode = SKLabelNode(text: "Hello World")
labelNode.fontSize = 20
labelNode.fontName = "San Fransisco"
labelNode.position = CGPoint(x:100,y:100)
skScene.addChild(rectangle)
skScene.addChild(labelNode)
  1. 创建您的平面并将场景设置为您的 Material 属性

例如

let plane = SCNPlane(width: 20, height: 20)
let material = SCNMaterial()
material.isDoubleSided = true
material.diffuse.contents = skScene
plane.materials = [material]
let node = SCNNode(geometry: plane)
scene.rootNode.addChildNode(node)
  1. 让你的场景动起来

例如

labelNode.run(SKAction.repeatForever(SKAction.rotate(byAngle: .pi, duration: 2)))

enter image description here

关于ios - 我如何在 ARkit 场景 iOS 中添加具有文本的 2dView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45317366/

相关文章:

ios - 将图像上传到 Firebase 并获取引用

swift - 使用 ActionSheet 中的 Collection View 显示照片

swift - 如何在 swift 中使用 char *c = "\x0D\x0A"

ios - 在 SCNNode 上加载 WebView CALayer 的问题

ios - iDevice 态度 : stabilising quaternion

ios - 约束 UIScrollView 平移?

ios - UIWebViewDelegate 方法未被调用

ios - OpenGL ES - GLSL 返回计算

swift 和火力地堡 |检查用户是否存在用户名

ios - 如何为单个图像设置多个选择选项?