Управление положением окон на мак в SwiftUI
Asked on 01/30/2025
1 search
To manage window positioning on macOS using SwiftUI, you can utilize the default window placement modifier. This allows you to programmatically set the initial position and size of a window. Here's a brief overview of how you can achieve this:
-
Calculate Position: You can calculate a position for the window manually by accessing the context, which contains information about the default display. This includes the visible rect, representing where it is safe to place content. You can then use this information to determine the window's position and size.
-
Default Window Placement API: This API allows you to specify an initial size and position for your window. You can use it to ensure that your window is placed in a comfortable position on the screen, such as centered horizontally and just above the bottom of the display.
-
Customization: You can further customize the window's behavior by changing how it can be resized or by using different scene types like utility windows.
For more detailed guidance, you can refer to the session Work with windows in SwiftUI (06:15) which covers window placement in detail.

Tailor macOS windows with SwiftUI
Make your windows feel tailor-made for macOS. Fine-tune your app’s windows for focused purposes, ease of use, and to express functionality. Use SwiftUI to style window toolbars and backgrounds. Arrange your windows with precision, and make smart decisions about restoration and minimization.

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.

What’s new in AppKit
Discover the latest advances in Mac app development. Get an overview of the new features in macOS Sequoia, and how to adopt them in your app. Explore new ways to integrate your existing code with SwiftUI. Learn about the improvements made to numerous AppKit controls, like toolbars, menus, text input, and more.