有谁知道如何清除 SceneView 3D 对象的背景?我正在尝试使用 UIColor.clear,但它使它变成白色。[
]
import SwiftUI
import SceneKit
struct TestView: View {
var body: some View {
ZStack{
Color.green
SceneView(
scene: {
let scene = SCNScene(named: "Earth.scn")!
scene.background.contents = UIColor.clear
return scene
}(),
options: [.autoenablesDefaultLighting,.allowsCameraControl]
)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2, alignment: .center)
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
Run Code Online (Sandbox Code Playgroud) 有谁知道如何更改 SceneView 对象的背景颜色?我尝试将背景属性放置到 SceneView 中,但它不会改变它,仍然具有默认背景。在这种情况下,我希望背景是绿色的,但它保持灰色/白色
import SwiftUI
import SceneKit
struct ContentView: View {
var body: some View {
ZStack{
Color.red
SceneView(
scene: SCNScene(named: "Earth.scn"),
options: [.autoenablesDefaultLighting,.allowsCameraControl]
)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2, alignment: .center)
.background(Color.green)
.border(Color.blue, width: 3)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)