2011-12-01 56 views
3

有没有办法将NSWindow创建为全屏模式? NSWindow拥有ToggleFullscreen:选择器,但它通常创建窗口并将其动画到全屏版本,这不是我想要的。任何其他方式做到这一点?以全屏模式创建NSWindow

回答

3

首先发现屏幕尺寸

NSRect screenRect; 
    NSArray *screenArray = [NSScreen screens]; 
    unsigned screenCount = [screenArray count]; 
    unsigned index = 0; 

    for (index; index < screenCount; index++) 
    { 
     NSScreen *screen = [screenArray objectAtIndex: index]; 
     screenRect = [screen visibleFrame]; 
    } 

screenRect包含屏幕尺寸,现在创造一个窗口,并设置NSWindow大小的屏幕尺寸。

unsigned int styleMask = NSTitledWindowMask 
          | NSMiniaturizableWindowMask; 


    myWindow = [NSWindow alloc]; 
    myWindow = [myWindow initWithContentRect: screenRect 
         styleMask: styleMask 
         backing: NSBackingStoreBuffered 
         defer: NO]; 
    [myWindow setTitle: @"This is a test window"]; 
+0

不只是这个窗口最大化,而不是把它变成全屏模式? – AndyTang

+0

请参阅http://cocoadevcentral.com/articles/000028.php和http://stackoverflow.com/questions/401240/display-os-x-window-full-screen-on-secondary-monitor-using-cocoa –

2
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 

    NSRect frame=[NSScreen mainScreen].frame ; 
    [self.window setFrame:frame display:YES animate:YES]; 
} 

这将在全屏幕打开窗口

+1

太棒了,但是如何设置一个应用程序来使用故事板进入全屏? – Olie