Creating NSWindow in fullscreen mode

2019-05-14 23:09发布

Is there a way to create a NSWindow into fullscreen mode? NSWindow has the ToggleFullscreen: selector but then it creates the window normally and animates it to the fullscreen version which isn't what I want. Any other way of doing it?

2条回答
放荡不羁爱自由
2楼-- · 2019-05-14 23:47

First find the screen size

    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 contain Screen size, now creat a window and set NSWindow size to screen size.

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"];
查看更多
叛逆
3楼-- · 2019-05-14 23:55
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

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

this will open window in full screen

查看更多
登录 后发表回答