Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAC OS Xcode Swift 2.2 Fullscreen Mode

What Swift code will switch the app to fullscreen? I found references with example code for IOS. I am looking for a code which works for a MacOS app.

like image 314
FJC Avatar asked Jul 02 '16 21:07

FJC


Video Answer


2 Answers

Updated for 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
}
like image 81
possen Avatar answered Nov 15 '22 03:11

possen


One way is to override viewDidAppear in 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()

like image 32
l'L'l Avatar answered Nov 15 '22 02:11

l'L'l