Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何解决';无法分配类型为';CATextLayerAlignmentMode';输入';字符串';?_Swift_Alignment_Scenekit_Arkit - Fatal编程技术网

Swift 如何解决';无法分配类型为';CATextLayerAlignmentMode';输入';字符串';?

Swift 如何解决';无法分配类型为';CATextLayerAlignmentMode';输入';字符串';?,swift,alignment,scenekit,arkit,Swift,Alignment,Scenekit,Arkit,如何解决“无法将“CATextLayerAlignmentMode”类型的值分配给具有此函数类型的“String”类型的问题 谢谢你的回答 Loïc我认为您需要用CATextLayerAlignmentMode.center.rawValue替换kCAAlignmentCenter您需要做的就是使用一个值CATextLayerAlignmentMode.center.rawValue。此值不仅在iOS中使用,在macOS中也使用 func createNewBubbleParentNode(_

如何解决“无法将“CATextLayerAlignmentMode”类型的值分配给具有此函数类型的“String”类型的问题

谢谢你的回答


Loïc

我认为您需要用
CATextLayerAlignmentMode.center.rawValue
替换
kCAAlignmentCenter
您需要做的就是使用一个值
CATextLayerAlignmentMode.center.rawValue
。此值不仅在iOS中使用,在macOS中也使用

func createNewBubbleParentNode(_ text: String) -> SCNNode {
    let billBoardConstraint = SCNBillboardConstraint()
    billBoardConstraint.freeAxes = SCNBillboardAxis.Y
    
    let bubble = SCNText(string: text, extrusionDepth: CGFloat(bubbleDepth))
    var font = UIFont(name: "Futura", size: 0.15)
    bubble.font = font
    bubble.alignmentMode = kCAAlignmentCenter
    
    return bubbleNodeParent
}
以下是完整的代码版本:

bubble.alignmentMode = CATextLayerAlignmentMode.center.rawValue

这太有用了!谢谢!!非常感谢你的回答!太有用了!!
import ARKit

class ViewController: UIViewController {

    @IBOutlet var sceneView: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        sceneView.scene = SCNScene()
        
        let textNode = self.createBubbleNode("SceneKit")
        sceneView.scene.rootNode.addChildNode(textNode)

        sceneView.session.run(ARWorldTrackingConfiguration())
    }
    
    func createBubbleNode(_ text: String) -> SCNNode {            
        let bubble = SCNText(string: text, extrusionDepth: 0.02)
        bubble.font = UIFont(name: "Futura", size: 0.15)
        bubble.firstMaterial?.diffuse.contents = UIColor.red
        bubble.alignmentMode = CATextLayerAlignmentMode.center.rawValue
        let bubbleNode = SCNNode(geometry: bubble)
        return bubbleNode
    }
}