所以我做了以下操作:
-
配置plist.info:
Application is agent(UIElement)
配置为";"是";(但可能只适用于iOS?(
wnd.collectionBehavior = [.stationary, .canJoinAllSpaces, .fullScreenAuxiliary]
wnd.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.maximumWindow)) + 2 )
NSApp.activate(ignoringOtherApps: true)
两人都无所事事!
所有可以帮助的是:
NSApp.setActivationPolicy(.prohibited)
但这对我来说不是解决方案,因为它禁用了应用程序的许多其他功能=(
有没有其他方法可以在全屏应用程序上方显示窗口?
完整代码:
func openMainWnd(show: Bool = true) {
if mainWndController == nil {
let styleMask: NSWindow.StyleMask = [ /*.closable,.miniaturizable, .resizable, .titled*/]
let wnd = NSWindow()
wnd.styleMask = styleMask
wnd.title = "Main1"
wnd.contentView = NSHostingView(rootView: MainView(model: appVm) )
wnd.standardWindowButton(.closeButton)?.isHidden = true
wnd.standardWindowButton(.miniaturizeButton)?.isHidden = true
wnd.standardWindowButton(.zoomButton)?.isHidden = true
wnd.isMovable = false
wnd.acceptsMouseMovedEvents = true
wnd.hasShadow = true
wnd.titleVisibility = .hidden
wnd.titlebarAppearsTransparent = true
wnd.backgroundColor = .clear
wnd.collectionBehavior = [.stationary, .canJoinAllSpaces, .fullScreenAuxiliary]
wnd.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.maximumWindow)) + 2 )
NSApp.activate(ignoringOtherApps: true)
wnd.setPosition(vertical: .top(offset: MainWndConfig.topOffset), horizontal: .center)
mainWndController = NSWindowController(window: wnd)
}
if show {
mainWndController?.showWindow(mainWndController?.window)
}
}
解决方案是使用NSPanel而不是NSWindow+.noactivingPanel+
从AppDelegate调用浮动NSPanel中视图的显示:
class AppDelegate: NSObject, NSApplicationDelegate {
var mainWndController: NSWindowController?
func openMainWnd(show: Bool = true) {
if mainWndController == nil {
let wnd = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 200, height: 200),
styleMask: [.nonactivatingPanel],
backing: .buffered,
defer: true)
wnd.orderFrontRegardless()
wnd.contentView = NSHostingView(rootView: MainView(model: appVm))
wnd.standardWindowButton(.closeButton)?.isHidden = true
wnd.standardWindowButton(.miniaturizeButton)?.isHidden = true
wnd.standardWindowButton(.zoomButton)?.isHidden = true
wnd.isMovable = false
wnd.acceptsMouseMovedEvents = true
wnd.hasShadow = true
wnd.titleVisibility = .hidden
wnd.titlebarAppearsTransparent = true
wnd.backgroundColor = .clear
wnd.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary] //[.stationary, .canJoinAllSpaces, .fullScreenAuxiliary]
wnd.level = .mainMenu
NSApp.activate(ignoringOtherApps: true)
wnd.setPosition(vertical: .top(offset: MainWndConfig.topOffset), horizontal: .center)
mainWndController = NSWindowController(window: wnd )
}
if show {
mainWndController?.showWindow(mainWndController?.window)
}
}
}
extension NSPanel {
// Allow panel to become key, that is, accepts keyboard events
// and give ability to use TextFields inside NSPanel
open override var canBecomeKey: Bool { true }
}