【发布时间】:2016-03-14 21:53:54
【问题描述】:
我需要在单击按钮时将 NSWindow.contentViewController 替换为新的 ViewController。为此,我编写了以下代码:
let g = GameViewController()
if self.window!.styleMask & NSFullScreenWindowMask != NSFullScreenWindowMask {
let ws = NSScreen.mainScreen()?.frame.size
let width : CGFloat = g.view.frame.width
let height : CGFloat = g.view.frame.height
let frame = NSRect(origin: NSMakePoint(((ws?.width)!-width)/2, ((ws?.height)!-height)/2), size: CGSize(width:width, height:height))
self.window?.setFrame(frame, display: true, animate: true)
}
self.window?.contentViewController = g
当 NSWindow 不处于全屏模式时,此代码运行良好。而当 NSWindow 处于 FullScreen 模式时,GameViewController 设置为默认大小,并且在发生调整大小事件之前不会改变大小。
如何实例化 NSViewController 以占用所有窗口空间?
【问题讨论】: