Search code examples
macosfullscreennswindow

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?


Solution

  • 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];
    }