MAC OS Xcode Swift 2.2全屏模式

时间:2016-07-02 21:53:50

标签: macos swift2 viewcontroller

什么Swift代码会将应用切换到全屏? 我找到了IOS示例代码的参考资料。 我正在寻找适用于MacOS应用程序的代码。

3 个答案:

答案 0 :(得分:3)

针对Swift 4进行了更新

override func viewDidAppear() {
    let presOptions: NSApplication.PresentationOptions = [.fullScreen, .autoHideMenuBar]
    let optionsDictionary = [NSView.FullScreenModeOptionKey.fullScreenModeApplicationPresentationOptions: presOptions]
    view.enterFullScreenMode(NSScreen.main!, withOptions: optionsDictionary)
    view.wantsLayer = true
}

答案 1 :(得分:3)

另一种选择,如果你想要不同的行为,当你将鼠标移动到顶部时,菜单栏是可用的。但是,它从正常大小的窗口开始然后增长,因此根据您正在做的事情可能不合适。

Plugin with id 'jp.classmethod.aws.lambda' not found.

答案 2 :(得分:2)

一种方法是覆盖viewDidAppear中的NSViewController

class ViewController : NSViewController {

    override func viewDidAppear() {
        let presOptions: NSApplicationPresentationOptions = ([.FullScreen,.AutoHideMenuBar])   
        let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions :
            NSNumber(unsignedLong: presOptions.rawValue)]
        self.view.enterFullScreenMode(NSScreen.mainScreen()!, withOptions:optionsDictionary)
        self.view.wantsLayer = true
        }
}

Apple Developer API Reference : viewDidAppear()