Post

Replies

Boosts

Views

Activity

How can I set the position of an app window on the screen for macOS with Swiftui?
I am trying to determine how to set the initial position of an app window for macOS. I have tried using NSViewRepresentable and .setFrameTopLeftPoint with no success. Is my syntax incorrect to achieve the desired results or should I be looking at some other method? struct WindowAccessor: NSViewRepresentable { @Binding var window: NSWindow? func makeNSView(context: Context) -> NSView { let view = NSView() view.window?.setFrameTopLeftPoint(CGPoint(x: 600, y: 400)) DispatchQueue.main.async { self.window = view.window } return view } func updateNSView(_ nsView: NSView, context: Context) {} } and var body: some Scene { WindowGroup { ContentView() .background(WindowAccessor(window: $window)) }
0
0
684
Nov ’21
How can I set the position of an app window on the screen for macOS with Swiftui?
I am trying to determine how to set the initial position of an app window for macOS. I have tried using NSViewRepresentable and .setFrameTopLeftPoint with no success. Is my syntax incorrect to achieve the desired results or should I be looking at some other method? struct WindowAccessor: NSViewRepresentable { @Binding var window: NSWindow? func makeNSView(context: Context) -> NSView { let view = NSView() view.window?.setFrameTopLeftPoint(CGPoint(x: 600, y: 400)) DispatchQueue.main.async { self.window = view.window } return view } func updateNSView(_ nsView: NSView, context: Context) {} } and var body: some Scene { WindowGroup { ContentView() .background(WindowAccessor(window: $window)) }
Replies
0
Boosts
0
Views
684
Activity
Nov ’21