Display os x window full screen on secondary monitor using Cocoa

后端 未结 3 1424
天涯浪人
天涯浪人 2020-12-05 05:49

I\'m working on a Cocoa Mac app where I need to display a window/view on a secondary monitor, full-screen. I know how to create a window that could be dragged onto the seco

3条回答
  •  无人及你
    2020-12-05 06:11

    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.

提交回复
热议问题