Управление положением окон на мак в SwiftUI
Generated on 1/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.

What’s new in SwiftUI
Learn how you can use SwiftUI to build great apps for any Apple platform. Explore a fresh new look and feel for tabs and documents on iPadOS. Improve your window management with new windowing APIs, and gain more control over immersive spaces and volumes in your visionOS apps. We’ll also take you through other exciting refinements that help you make expressive charts, customize and layout text, and so much more.

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.