【问题标题】:NSWindow LocationNSWindow 位置
【发布时间】:2019-10-28 04:48:10
【问题描述】:

我正在以编程方式创建一个需要跨越 2 个屏幕的窗口。正在创建的窗口的大小是正确的,但窗口大约在第一个屏幕的一半处开始。我可以将它拖回第一个屏幕的开头,并且 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!)
} 

【问题讨论】:

    标签: swift macos nswindow


    【解决方案1】:

    您正在设置内容矩形,但没有设置框架。框架是窗口在屏幕坐标中占据的矩形。要移动窗口,您可以setFrameOrigin()setFrameTopLeftPoint()

    【讨论】:

    • 内容矩形也在屏幕坐标中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 2010-11-30
    • 1970-01-01
    相关资源
    最近更新 更多