How to open and close windows and volumes programmatically in VisionOS

Oscar de la Hera Gomez
A flower that represents VisionOS with the text “Open and Close Windows & Volumes” beneath it.

To open and close windows and volumes, add them to the app and use the openWindow and dismissWindow environment variables within a button.

The code for this tutorial can be found in the repository linked below on the 101/opening-and-closing-windows branch.

Please note that this tutorial focuses on closing windows and volumes through buttons external to the window or volume.

You can always use the x button at the bottom of a window or volume to close it.

Step One: Setup the Entities

A screenshot of the simulator showing multiple windows and volumes.

Follow the tutorial below to learn how to open volumes and windows.

Step Two: Create a Dynamic Button

A screenshot of XCode showing the code for the dynamic button.

Create a new file that holds a button that opens and dismisses windows depending on the id that is passed in.

Please note that this functionality opens and closes volumes too.

Step Three: Update the Main Window

A screenshot of XCode showing the updated code for the main window which now features the dynamic button.

Update the window to use the button created in Step Two.

Step Four: Test

A screenshot of the simulator showing that a second window is open and the button says "close window" instead of "open window".

The simulator can now open windows.

Run the code and make sure you can open and close windows and volumes.

A screenshot of the simulator showing that the window is now closed and the button says "open window" instead of "close window".

The simulator can now close windows.

Looking to learn more about VisionOS, Spatial Computing, Design and Technology?

Search our blog to learn more about visionOS, spatial computing, design and technology.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details