如何全屏开始NSWindow

时间:2014-06-10 15:42:47

标签: macos fullscreen nswindow

我正在为Xcode5开发适用于Mac OSX的应用程序

我希望全屏显示我的第一个窗口(仅我的视图没有工具栏)

我找到了一种在角落显示全屏按钮的方法:

AppDelegate.m:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    screenFrame = [[NSScreen mainScreen] frame];

    [self.window setBackgroundColor: NSColor.whiteColor];
    [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    [[self window] setFrame:screenFrame display:YES];
}

但为了全屏,我必须点击角落的按钮

enter image description here

如何全屏保存按下该按钮的步骤?

2 个答案:

答案 0 :(得分:8)

添加[self.window toggleFullScreen:self];

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    screenFrame = [[NSScreen mainScreen] frame];

    [self.window setBackgroundColor: NSColor.whiteColor];
    [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    [self.window setFrame:screenFrame display:YES];
    [self.window toggleFullScreen:self];
}

答案 1 :(得分:2)

快速版本:

let screenFrame = NSScreen.main?.frame
self.window?.collectionBehavior = NSWindow.CollectionBehavior.fullScreenPrimary
self.window?.setFrame(screenFrame!, display: true)
self.window?.toggleFullScreen(self)