visionOS – 可以在沉浸式空间之外使用RealityView吗?

huangapple go评论39阅读模式
英文:

visionOS - Can you use a RealityView outside of an ImmersiveSpace?

问题

I have a visionOS app that supports both a WindowGroup and an ImmersiveSpace.

import SwiftUI

@main
struct VisionApp: App {
    
    @State var immersionStyle: ImmersionStyle = .mixed
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        
        ImmersiveSpace(id: "MySpace") {
            MySpace()
        }
        .immersionStyle(selection: $immersionStyle, in: .mixed)
        
    }
}

The window is a normal window. I am able to load up my SwiftUI views and also use other apps like Safari. I have a button to launch the ImmersiveSpace.

The ImmersiveSpace is not fully immersive. There are a few models and particle emitters, but otherwise you can still see all of your actual surroundings. I can still see my app's window, but unfortunately it appears that when you launch an ImmersiveSpace it causes all other apps to be backgrounded.

I've tried putting RealityView inside a WindowGroup, but it does not seem to work:

WindowGroup {
    RealityView {
        /// ...
        /// ...
}

I suspect this is intended behavior and a limitation of ImmersiveSpace, but I am asking to be sure.

英文:

I have a visionOS app that supports both a WindowGroup and an ImmersiveSpace.

import SwiftUI

@main
struct VisionApp: App {
    
    @State var immersionStyle: ImmersionStyle = .mixed
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        
        ImmersiveSpace(id: "MySpace") {
            MySpace()
        }
        .immersionStyle(selection: $immersionStyle, in: .mixed)
        
    }
}

The window is a normal window. I am able to load up my SwiftUI views and also use other apps like Safari. I have a button to launch the ImmersiveSpace.

The ImmersiveSpace is not fully immersive. There are a few models and particle emitters, but otherwise you can still see all of your actual surroundings. I can still see my app's window, but unfortunately it appears that when you launch an ImmersiveSpace it causes all other apps to be backgrounded.

I've tried putting RealityView inside a WindowGroup, but it does not seem to work:

WindowGroup {
    RealityView {
        /// ...
        /// ...
}

I suspect this is intended behavior and a limitation of ImmersiveSpace, but I am asking to be sure.

答案1

得分: 1

你可以在常规窗口和音量中都使用 RealityView。我刚刚尝试将 RealityView 放置在这两者中的每一个,都可以正常工作。也许可以发布更多你的代码?

英文:

You can use a RealityView in both a regular window and a volume. I just tried placing a RealityView in each of these, and it works fine. Maybe post more of your code?

huangapple
  • 本文由 发表于 2023年7月3日 07:02:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定