Presenter: Haotian Zheng, SwiftUI Engineer
Link: https://developer.apple.com/wwdc24/10148
New SwiftUI APIs to tailor your macOS windows
Check out: Work with Windows in SwiftUI
@main
struct DestinationVideo: App {
var body: some Scene {
WindowGroup(id: "catalog") {...}
Window("About Destination Video", id: "about") {...}
WindowGroup("Video Player", id: "player") {...}
}
}
Remove title:
.toolbar(removing: title)
Remove toolbar background:
.toolbarBackgroundVisibility(.hidden, for: .windowToolbar)
Add container background:
.containerBackground(.thickMaterial, for: .window)
Customize the minimize behavior:
.windowMinimizeBehavior(.disabled)
Customize the restoration behavior:
.restorationBehavior(.disabled)
Default placement:
.defaultWindowPlacement { content, context in
var size = content.sizeThatFits(.unspecified)
let displayBounds = context.defaultDisplay.visibleRect
// modify size based on display bounds
return WindowPlacement(size: size)
}
Ideal placement:
.windowIdealPlacement { content, context in
var size = content.sizeThatFits(.unspecified)
let displayBounds = context.defaultDisplay.visibleRect
// modify size based on display bounds
return WindowPlacement(size: size)
}
.windowStyle(.plain)
.defaultLaunchBehavior(.presented)