How do I create a utility window in visionOS

Generated on 8/1/2024

1 search

To create a utility window in visionOS, you can follow these steps as outlined in the session "Work with windows in SwiftUI":

  1. Define a Window Group: Start by adding a new window group that will contain the content for your utility window. You can give this window group an identifier to manage it easily.

  2. Open the Window: Use the openWindow action to open the window. This action can be called from anywhere in the SwiftUI hierarchy.

  3. Customize the Window Placement: Use the defaultWindowPlacement modifier to set the initial position and size of the window. For a utility window, you can use the utilityPanel position, which places the window close by and generally within direct touch range.

Here is a brief example based on the provided context:

struct ContentView: View {
    @Environment(\.openWindow) private var openWindow

    var body: some View {
        Button("Open Utility Window") {
            openWindow(id: "utilityWindow")
        }
    }
}

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .windowGroup(id: "utilityWindow") {
            UtilityWindowView()
        }
        .defaultWindowPlacement(.utilityPanel)
    }
}

For more detailed information, you can refer to the session Work with windows in SwiftUI at the timestamp 07:27.

Design great visionOS apps

Design great visionOS apps

Find out how to create compelling spatial computing apps by embracing immersion, designing for eyes and hands, and taking advantage of depth, scale, and space. We’ll share several examples of great visionOS apps and explore how their designers approached creating new experiences for the platform.

Design interactive experiences for visionOS

Design interactive experiences for visionOS

Learn how you can design a compelling interactive narrative experience for Apple Vision Pro from the designers of Encounter Dinosaurs. Discover how these types of experiences differ from existing apps, media, and games, and explore how to design narratives that bring audiences into new worlds. Find out how you can create stories that adapt to any space and size, provide multiple levels of interaction to make them accessible to all, and use animation, spatial audio, and custom gestures to further immerse people in your experience.

Get started with HealthKit in visionOS

Get started with HealthKit in visionOS

Discover how to use HealthKit to create experiences that take full advantage of the spatial canvas. Learn the capabilities of HealthKit on the platform, find out how to bring an existing iPadOS app to visionOS, and explore the special considerations governing HealthKit during a Guest User session. You’ll also learn ways to use SwiftUI, Swift Charts, and Swift concurrency to craft innovative experiences with HealthKit.

Work with windows in SwiftUI

Work with windows in SwiftUI

Learn how to create great single and multi-window apps in visionOS, macOS, and iPadOS. Discover tools that let you programmatically open and close windows, adjust position and size, and even replace one window with another. We’ll also explore design principles for windows that help people use your app within their workflows.