How do I use the Utility window placement in visionOS

Asked on 08/06/2024

2 searches

To use the Utility window placement in visionOS, you can follow these steps as described in the session "Work with windows in SwiftUI":

  1. Add a New Window Group: Create a new window group for your controls or utility panel.
  2. Open the Window Programmatically: Use the open window call to open your controls in a new window.
  3. Set Default Window Placement: Apply the default window placement modifier to the window group. This allows you to set the initial position and size of the window programmatically.
  4. Specify Utility Panel Position: Return a window placement with a position of utility panel. This places the window close by and generally within direct touch range.

Here is a relevant segment from the session:

"In visionOS, to make the game controls appear close to the player, I applied the default window placement modifier to the controller window group. From this, I return a window placement with a position of utility panel. I wrap this return in an if condition so that this placement is only applied for visionOS. Now the controls appear close by when the window is first opened, and the player is able to move the window from its initial placement if they like." (Work with windows in SwiftUI)

For more detailed information, you can refer to the "Placement" chapter in the session "Work with windows in SwiftUI".

Relevant Sessions

  1. Work with windows in SwiftUI
  2. Design interactive experiences for visionOS