小编fel*_*ode的帖子

如何在 SwiftUI 中清除 SceneView 3D 对象的背景

有谁知道如何清除 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)

xcode swift scnscene sceneview swiftui

5
推荐指数
1
解决办法
759
查看次数

如何在 SwiftUI 中更改 SceneView 3D 对象的背景颜色

有谁知道如何更改 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)

xcode scenekit swift swiftui

4
推荐指数
1
解决办法
1801
查看次数

标签 统计

swift ×2

swiftui ×2

xcode ×2

scenekit ×1

sceneview ×1

scnscene ×1