How can I set the position of the spawn point of the SwiftUI panel?

My project has integrated SwiftUI panel , I noticed that when I open the SwiftUI interface, it always appears in front of me and stays at a certain distance. I want it to spawn on my left side instead, and with some rotation. How can I set the position in the code to achieve this?

Answered by Vision Pro Engineer in 790737022

Hey @YimingLi,

You have a few options. New in visionOS 2.0 is the defaultWindowPlacement API. This allows you to specify a default location in space for when the window first appears. After appearing your users can later resize and move the window using interface controls that the system provides.

Another option is using Attachments on RealityView. With attachments, the system controls are no longer present so users are unable to move the window. You can set the position and rotation on attachment entities just like your other entities. Diorama has some great example code showing this in practice.

Thanks for your question,

Michael

Hey @YimingLi,

You have a few options. New in visionOS 2.0 is the defaultWindowPlacement API. This allows you to specify a default location in space for when the window first appears. After appearing your users can later resize and move the window using interface controls that the system provides.

Another option is using Attachments on RealityView. With attachments, the system controls are no longer present so users are unable to move the window. You can set the position and rotation on attachment entities just like your other entities. Diorama has some great example code showing this in practice.

Thanks for your question,

Michael

How can I set the position of the spawn point of the SwiftUI panel?
 
 
Q