Hi, i am trying to design an absolutely simple MacOS app whose window cannot be changed or can only be changed to a certain extent. So by grabbing the borders, edges and corners. Unfortunately, it doesn't work at all. The Apple documentation is quite straightforward: https://developer.apple.com/documentation/visionOS/positioning-and-sizing-windows Work with XCode 16.2 on Mac Mini M1 with MacOS 15.2 ... and less developer experience ;-) Does anyone have any ideas? Does it perhaps not comply with the UI guidelines? Greetings, Oliver
Thanks to chatGPT ... I'll post the finished basic structure for the window here. It's technically the window you see when you click on the Apple logo to open the “About this Mac” function ....
@main
struct FixedSizeWindowApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
EmptyView() // No additional content required as the window is managed by AppDelegate
}
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
func applicationDidFinishLaunching(_ notification: Notification) {
// Create Window
let windowRect = NSRect(x: 0, y: 0, width: 1600, height: 1000)
window = NSWindow(
contentRect: windowRect,
styleMask: [.titled, .closable], // Title bar and close button
backing: .buffered,
defer: false
)
// Window properties
window.center() // Center window
window.title = "About this Mac" // Set title
window.isReleasedWhenClosed = false // Keep window
window.isMovableByWindowBackground = true // Movable window
// Fixed window size
window.minSize = windowRect.size
window.maxSize = windowRect.size
// Contents of the window with SwiftUI
let hostingView = NSHostingView(rootView: ContentView())
hostingView.frame = window.contentView!.bounds
hostingView.autoresizingMask = [.width, .height]
window.contentView = hostingView
// Show Window
window.makeKeyAndOrderFront(nil)
}
func applicationWillTerminate(_ notification: Notification) {
// Insert cleanup functions etc.
}
}
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "applelogo")
.font(.system(size: 50))
.padding()
Text("About this Mac")
.font(.title)
.bold()
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
Happy holidays, Oliver