【问题标题】:Change macOS window level with SwiftUI (to make a floating window)使用 SwiftUI 更改 macOS 窗口级别(制作浮动窗口)
【发布时间】:2021-03-13 23:42:45
【问题描述】:

嗨,有没有办法用 SwiftUI 更改 window level,这样我就可以为我的 mac 应用程序制作一个浮动窗口?我正在使用 SwiftUI 生命周期

【问题讨论】:

    标签: swift macos swiftui nswindow


    【解决方案1】:

    您可以使用NSApplication.shared.windows 访问您的窗口,并为每个窗口设置level。

    例如:

    Button("Float windows") {
        for window in NSApplication.shared.windows {
            window.level = .floating
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      相关资源
      最近更新 更多