2011-12-01 57 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