如何在MacOS 桌面上的 SwiftUI 中设置窗口坐标?例如,窗口应该始终出现在中心还是始终出现在右上角?
这是我的版本,但是,我移动代码并关闭它,当我打开它时,它首先出现在旧位置,然后跳转到新位置。
import SwiftUI
let WIDTH: CGFloat = 400
let HEIGTH: CGFloat = 200
@main
struct ForVSCode_MacOSApp: App {
@State var window : NSWindow?
var body: some Scene {
WindowGroup {
ContentView(win: $window)
}
}
}
struct WindowAccessor: NSViewRepresentable{
@Binding var window: NSWindow?
func makeNSView(context: Context) -> some NSView {
let view = NSView()
let width = (NSScreen.main?.frame.width)!
let heigth = (NSScreen.main?.frame.height)!
let resWidth: CGFloat = (width / 2) - (WIDTH …Run Code Online (Sandbox Code Playgroud)