Livid
289.86D
543.25D
V2EX  ›  Swift

SwiftUI 做的 macOS App 里,如果用 CMD+W 关闭窗口,然后点击 Dock 上的图标重开,窗口尺寸不会被记住

  •  
  •   Livid ·
    PRO
    · Jun 5, 2022 · 4326 views
    This topic created in 1472 days ago, the information mentioned may be changed or developed.
    这里有一个关于这个问题的带图描述:

    https://developer.apple.com/forums/thread/702465

    这个问题在目前版本( Xcode 13 + macOS 12 )的 SwiftUI 里有解决方法么?
    Supplement 1  ·  Jun 5, 2022
    WindowGroup 中创建的窗口,如果是用 CMD+W 关闭,似乎也无法记住最后的位置和尺寸。
    5 replies    2022-08-28 11:55:15 +08:00
    dingwen07
        1
    dingwen07  
       Jun 5, 2022
    我试了一下应该是 SwiftUI 的 Telegram for macOS ,窗口尺寸和位置会保持
    源代码: https://github.com/overtake/TelegramSwift
    dingwen07
        2
    dingwen07  
       Jun 5, 2022
    忽略#1 ,这个不是 swift ui
    chipmuck
        3
    chipmuck  
       Jun 8, 2022   ❤️ 1
    macOS 13.0+ 似乎可以通过 Window 和 Scene 上的 defaultPosition 和 defaultSize 来处理了。

    https://developer.apple.com/documentation/swiftui/window/scene-implementations
    https://developer.apple.com/videos/play/wwdc2022/10052/
    Livid
        4
    Livid  
    MOD
    OP
    PRO
       Aug 28, 2022
    最近又看了一下这个问题,有一些新的发现。

    macOS 恢复窗口尺寸的依据是 frameAutosaveName 。

    而用 SwiftUI 创建的 window ,在每次 CMD+W 关闭又打开之后,会获得一个新的 frameAutosaveName 。

    所以,理论上,如果能够让开发者自己固定 SwiftUI 的 frameAutosaveName 这个值,应该这个问题就解决了。

    xlsepiphone
        5
    xlsepiphone  
       Aug 28, 2022
    野路子就是自己存一下窗口大小和坐标,打开的时候手动设置一下。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5882 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 03:09 · PVG 11:09 · LAX 20:09 · JFK 23:09
    ♥ Do have faith in what you're doing.