21

I have been trying to make my Mac application enter fullscreen now for a while but can't get it to work. According to the Apple developer center, I should use enterFullScreenMode:withOptions: which gives me, method enterFullScreenMode not found.

Everywhere I google there seems to be people having issues with making their app fullscreen, so what is the way to make it work?

Edit:

Of course enterFullScreenMode is for the NSView and I used it on a NSWindow; it's not the view I want to have fullscreen, but the window. I can't find any function for the NSWindow though.

Gabe
  • 84,912
  • 12
  • 139
  • 238
tobros91
  • 668
  • 1
  • 9
  • 24
  • make the contentView of the NSWindow enter full screen. – hauntsaninja Feb 07 '11 at 14:32
  • I've been reading around (http://www.cocoabuilder.com/archive/cocoa/201569-nsview-enterfullscreenmode-withoptions-woes-window-levels.html), and it seems like `enterFullScreenMode:withOptions:` is nearly useless, if you want to do anything useful. I think that you are going to have to use some Carbon-nastiness, if you want control over animated-transitions, window level, menubar/dock unhiding, etc. – Jonathan Sterling Feb 07 '11 at 14:36
  • 4
    just use `[[window contentview] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];` and you can do *everything* you can do with a normal NSView, including adding CoreAnimation layers and OpenGL layers/views. – hauntsaninja Feb 07 '11 at 14:38
  • 2
    @Jonathan Sterling: No Carbon needed IIRC — just a handful of CoreGraphics functions. I agree the API is a little bit imposing, but it's actually not that bad. – Chuck Feb 07 '11 at 18:31
  • @Chuck Awesome, my mistake. Thanks! (Anyone reading this, just ignore what I wrote before!) – Jonathan Sterling Feb 07 '11 at 23:58

4 Answers4

21

Lion has some new APIs for full screen.

To do it with NSWindow, do this

[window setCollectionBehavior:
          NSWindowCollectionBehaviorFullScreenPrimary];

To do this with NSApplication do this

[[NSApplication sharedApplication]
        setPresentationOptions:NSFullScreenWindowMask];

A bit more about it here.

Randall
  • 14,691
  • 7
  • 40
  • 60
13

Modern day Mac Os X developers (who use storyboard) need only to click on their main.storyboard, select the NSWindow (not the NSWindowController), Use the right panel to find the attributes panel (the one that to the left of the ruler, it looks like a drag-bar thing) look for "Full Screen" and select "Primary Window" rather than its default value of "Unsupported". You can also set up Auxiliary windows if that's what you want.

Don't fight the change, use storyboard. One of us... one of us...

Ethan
  • 1,567
  • 11
  • 16
  • You can also do this with plain old XIBs (NIBs). You don't need storyboards. How do you handle document-based applications in storyboards? I found the defaults really annoying, the way the document was split out into a separate scene - it added extra work so I had to wire up the document to my view controllers in code, so the storyboard felt incomplete. For iOS apps I still do mostly views-in-code as I'm not a fan of segues and I'm much more efficient in code. For Mac apps, I'm tending to use NIBs but I still need to write some view code. – Joel Dec 29 '14 at 08:34
  • @Ethan, can't see Unsupported value, does fullscreen is a mandatory now? – Dima Deplov Nov 30 '15 at 14:20
7

As mentioned in the link Jonathan provided in the comments, enterFullScreen:withOptions: has a number of drawbacks that can make you want to tear your hair out. The best way to do fullscreen is still the older CGDirectDisplay API. Cocoa Dev Central has an article on fullscreen apps that covers pretty much everything you need to know.

You'll notice the article is pretty ancient and the dev tools have changed a lot since then (Project Builder! Ah, the good old days), but the code itself will still work.

Chuck
  • 234,037
  • 30
  • 302
  • 389
0
[self.view setFrame:[[NSScreen mainScreen] visibleFrame]];
Luke
  • 11,426
  • 43
  • 60
  • 69
Subhash
  • 545
  • 7
  • 11