我正在以编程方式创建一个窗口,需要跨越两个屏幕。创建的窗口大小正确,但窗口从第一个屏幕中间开始。我可以将其拖回到第一个屏幕的起始位置,NSWindow 就能完美地展示。
我只需要知道窗口的起始点在哪里出了问题。
我只需要知道窗口的起始点在哪里出了问题。
func createNewWindow() {
let bannerWidth = NSScreen.screens[0].frame.width * 2
let bannerHeight = NSScreen.screens[0].frame.height
let rect = CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: bannerWidth, height: bannerHeight))
let newWindow = NSWindow(contentRect: rect, styleMask: [.closable], backing: .buffered, defer: false)
let storyboard = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "ExternalScreen") as? NSViewController
let window = storyboard?.view
newWindow.styleMask.update(with: .resizable)
NSMenu.setMenuBarVisible(false)
newWindow.title = "New Window"
newWindow.isOpaque = false
newWindow.isMovableByWindowBackground = true
newWindow.backgroundColor = NSColor(calibratedHue: 0, saturation: 1.0, brightness: 0, alpha: 0.7)
newWindow.toggleFullScreen(true)
newWindow.makeKeyAndOrderFront(nil)
newWindow.toolbar?.isVisible = false
newWindow.contentView?.addSubview(window!)
}