Display os x window full screen on secondary monitor using Cocoa

好久不见. 提交于 2019-11-27 19:31:41

First, determine which screen you want to use by iterating over [NSScreen screens].

Create a full screen window with:

NSScreen *screen = /* from [NSScreen screens] */
NSRect screenRect = [screen frame];
NSWindow *window = [[NSWindow alloc] initWithContentRect:screenRect
    styleMask:NSBorderlessWindowMask
    backing:NSBackingStoreBuffered
    defer:NO
    screen:screen];
[window setLevel: CGShieldingWindowLevel()];

You might want to google CGDisplayCapture() as well.

You can call the enterFullScreenMode:withOptions: method of NSView to acheieve the desired behaviour.

See Apple's documentation.

Read here and here for the options that can be supplied to this method.

You can use [NSScreen screens] to get the list of available screens. See here for details.

The full screen window animations are choppy and don't look good in my opinion. The fullscreen view is much smoother.

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.

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