[英]Set NSViewController to fullscreen
我的ViewController包含一個按鈕。 當按下按鈕時,執行以下行:
self.window?.styleMask = NSFullScreenWindowMask
self.window?.setFrame((NSScreen.mainScreen()?.frame)!, display: true, animate: true)
self.window?.contentViewController = Game()
理想情況下,當按下按鈕時,Windows內容將替換為名為Game的新NSViewController。
即使將窗口動畫化為全屏模式,游戲也會在屏幕角落顯示(僅為500 * 300px),並且窗口也不處於全屏模式。 如何更改窗口的內容並將其設置為全屏樣式?
只需將NSView的自動調整大小蒙版設置為可調整的寬度和高度即可:
self.view.autoresizingMask = NSViewHeightSizable | NSViewWidthSizable;
就我而言,我被告知以下答案:
let currentBounds = contentViewController!.view.bounds.size
let destVCNew = destVC as? CPViewController
// Important, missing part:
destVCNew?.view.frame = CGRect(origin: CGPointZero, size: currentBounds)
self.contentViewController = destVCNew
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.