Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to begin NSWindow in fullscreen

I am developing an app for Mac OSX in Xcode5

and I want to display my first Window in fullscreen (no toolbar just my view)

I found a way to display a button on the corner for fullscreen:

AppDelegate.m:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    screenFrame = [[NSScreen mainScreen] frame];

    [self.window setBackgroundColor: NSColor.whiteColor];
    [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    [[self window] setFrame:screenFrame display:YES];
}

but to get fullscreen I have to click on the corner's button

enter image description here

how to get fullscreen saving the step of pressing that button?

like image 798
Jesus Avatar asked Jun 10 '14 15:06

Jesus


2 Answers

add this [self.window toggleFullScreen:self];

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    screenFrame = [[NSScreen mainScreen] frame];

    [self.window setBackgroundColor: NSColor.whiteColor];
    [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    [self.window setFrame:screenFrame display:YES];
    [self.window toggleFullScreen:self];
}
like image 88
Jesús Ayala Avatar answered Oct 07 '22 13:10

Jesús Ayala


Swift Version:

let screenFrame = NSScreen.main?.frame
self.window?.collectionBehavior = NSWindow.CollectionBehavior.fullScreenPrimary
self.window?.setFrame(screenFrame!, display: true)
self.window?.toggleFullScreen(self)
like image 24
BackSpace Avatar answered Oct 07 '22 11:10

BackSpace