Cocoa 应用程序默认为全屏?

发布于 2024-12-11 19:09:52 字数 96 浏览 3 评论 0原文

我看过大量关于向 NSWindow 添加控件以使其能够进入全屏的帖子 - 通过代码和 Interface Builder 设置。我正在寻找的是当应用程序启动时,它默认以全屏打开。

I've seen a ton of posts about adding a control to a NSWindow to give it the ability to go into full-screen — both through code and Interface Builder settings. What I'm looking for is when the application is launched, it opens in full-screen by default.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无敌元气妹 2024-12-18 19:09:52

设置主窗口的委托。如果您还没有窗口委托,则可以使用应用程序委托作为窗口委托。然后将此方法添加到窗口委托中:

- (void)windowDidBecomeMain:(NSNotification *)notification
{
    static BOOL shouldGoFullScreen = YES;
    if (shouldGoFullScreen) {
        if (!([self.window styleMask] & NSFullScreenWindowMask))
            [self.window toggleFullScreen:nil];
        shouldGoFullScreen = NO;
    }
}

Set your main window's delegate. You can use your app delegate as the window delegate if you don't already have a window delegate. Then add this method to the window delegate:

- (void)windowDidBecomeMain:(NSNotification *)notification
{
    static BOOL shouldGoFullScreen = YES;
    if (shouldGoFullScreen) {
        if (!([self.window styleMask] & NSFullScreenWindowMask))
            [self.window toggleFullScreen:nil];
        shouldGoFullScreen = NO;
    }
}
溇涏 2024-12-18 19:09:52

如果您正在为旧版本的操作系统编码。您可以使用下面的代码。此代码适用于 10.6 mac lion onwords。

 [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
 [[NSApplication sharedApplication] setPresentationOptions:NSFullScreenWindowMask];

If you are coding for older versions of OS. you can use the below code.This code will work from 10.6 mac lion onwords.

 [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
 [[NSApplication sharedApplication] setPresentationOptions:NSFullScreenWindowMask];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文