Are there any example on how to write full-screen

2019-04-16 14:40发布

问题:

Could someone point me to any examples on how to write full-screen apps for Mac OS X in Ojective-C with Cocoa?

回答1:

Add the following code to the NSView you want to make fullscreen:

[view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];

It's exactly the same, the only thing you need to watch for is if you have any NSWindow specific code...

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html



回答2:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02

There is an OSX Cocoa example for many of the tutorials.



回答3:

Try this:

- (void)toggleMyViewFullScreen:(id)sender
{
    if (myView.inFullScreenMode) {
      [myView exitFullScreenModeWithOptions:nil];
    } else {
      NSApplicationPresentationOptions options =
          NSApplicationPresentationHideDock |       
          NSApplicationPresentationHideMenuBar;

      [myView enterFullScreenMode:[NSScreen mainScreen] withOptions:@{
             NSFullScreenModeApplicationPresentationOptions : @(options) }];
                                                                                 }];
    }
}

You can connect this to the fullscreen menu item in the Window menu (after inserting that into your nib) but be sure to change the action that the menu item fires to your toggleMyViewFullScreen: . Or your can invoke toggleMyViewFullScreen programmatically or when your app loads.