Creating NSWindow in fullscreen mode

天大地大妈咪最大 提交于 2019-12-10 10:15:34

问题


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?


回答1:


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"];



回答2:


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

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

this will open window in full screen



来源:https://stackoverflow.com/questions/8338314/creating-nswindow-in-fullscreen-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!