How to make a Mac OSX Cocoa application fullscreen?

左心房为你撑大大i 提交于 2019-12-02 19:05:21

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.

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.

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...

Subhash
[self.view setFrame:[[NSScreen mainScreen] visibleFrame]];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!