如何在Swift UI中添加3D形状?

问题描述 投票:0回答:1

我想知道如何在快速UI中添加3D形状(例如Sphere)>

我曾尝试添加一个场景并在迅速的用户界面中使用它,但收到错误消息

//SceneKit

class myscene: SCNScene{
 override init(){
     super.init()
 }
 required init?(coder: NSCoder) {
     fatalError("init(coder: ) has not been implemented")
 }
}

//Swift UI 

struct ContentView: View {
 var body: some View {

     let sphere = SCNSphere(radius: 2.0)
     sphere.firstMaterial?.diffuse.contents = UIColor.blue
     let spherenode = SCNNode(geometry: sphere)
     spherenode.position = SCNVector3(x: 0.0, y: 3.0, z: 0.0)
 }
}

错误消息在var body: some View {行上,内容如下:

Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type

请帮助我解决这个问题......

我想知道如何在swift UI中添加3D形状(例如Sphere),我曾尝试添加scnscene并在swift UI中使用它,但我收到一条错误消息// SceneKit类myscene:SCNScene {覆盖init(。 。

swift scenekit swiftui swift-playground swift5
1个回答
0
投票

这是最简单的代码,用于演示如何使用球体设置SceneKit场景。希望对您有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.