我正在以编程的方式创建一个需要跨越两个屏幕的窗口。正在创建的窗口的大小是正确的,但是窗口大约在第一个屏幕的一半处开始。我可以把它拖回第一个屏幕的开头,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!)
} 发布于 2019-10-28 05:18:19
您正在设置内容矩形,而不是设置框架。框架是窗口在屏幕坐标中占据的矩形。要移动窗口,可以使用setFrameOrigin()或setFrameTopLeftPoint()。
https://stackoverflow.com/questions/58585905
复制相似问题