Swift 如何解决';无法分配类型为';CATextLayerAlignmentMode';输入';字符串';?
如何解决“无法将“CATextLayerAlignmentMode”类型的值分配给具有此函数类型的“String”类型的问题 谢谢你的回答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(_
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
}
}