swift - How can i add a 2dView having text in ARkit scene iOS -
how can add 2dview having text in arkit scene ios.how can add view in top of node won't rotate when rotate node.
you can add scnplane
, use scnlookatconstraint
plane looks @ camera.
you can create custom material , set it's material properties to:
a color (uicolor or cgcolor), specifying constant color across material’s surface number (
an image (uiimage or cgimage), specifying texture mapped across material’s surface
- a core animation layer (calayer)
- a texture (sktexture, mdltexture, mtltexture, or glktextureinfo)
- a spritekit scene (skscene)
you can display animated contents using coreanimation or spritekit but
scenekit cannot use layer being displayed elsewhere (for example, backing layer of uiview object)
here example using spritekit:
- create spritekit scene:
e.g.:
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)
- create plane , set scene material property
e.g.
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)
- animate scene
e.g.
labelnode.run(skaction.repeatforever(skaction.rotate(byangle: .pi, duration: 2)))
Comments
Post a Comment