2008-12-30 46 views
12

我正在研究Cocoa Mac应用程序,我需要在辅助显示器上全屏显示窗口/视图。我知道如何创建一个可以拖动到辅助显示器上的窗口,但我希望以编程方式创建窗口并将其全屏显示在外部显示器上。谢谢您的帮助。使用Cocoa在辅助显示器上显示os x窗口全屏

回答

12

首先,通过迭代[NSScreen screens]来确定您想要使用哪个屏幕。

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()]; 

你可能想谷歌CGDisplayCapture(),以及:

与创建一个全屏窗口。

+0

谢谢你,这很好。由于我试图输出到次屏幕,我只是使用[窗口setLevel:NSStatusWindowLevel]; – Austin 2008-12-30 23:35:02

4

您可以拨打enterFullScreenMode:withOptions:方法NSView以获得所需的行为。

请参阅Apple's documentation

阅读herehere了解可以提供给此方法的选项。

您可以使用[NSScreen screens]来获取可用屏幕的列表。详情请参阅here

+0

谢谢你的帮助。对于我正在尝试做的事情,我认为第一种解决方案对我来说最合适,但我必须牢记该观点全屏方法。 – Austin 2008-12-30 23:33:03

0

全屏窗口动画不稳定,在我看来不好看。全屏视图更平滑。

试试这个:

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

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

您可以在此连接到窗口菜单的全屏菜单项(插入的是到您的笔尖后),但一定要更改操作的菜单项火灾您toggleMyViewFullScreen :。或者,您可以以编程方式或加载应用时调用toggleMyViewFullScreen。

相关问题