问题
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