进入全屏模式时显示 NSToolbar

发布于 2025-01-05 10:23:16 字数 987 浏览 5 评论 0原文

我正在开发一个应用程序,用户可以使用按钮显示/隐藏工具栏。问题如下:如果用户选择隐藏工具栏,然后进入全屏模式,则会显示工具栏。

用户界面是通过编程方式创建的(即不使用 Interface Builder)。

这是应用程序委托中的工具栏创建:

mainToolbar = [[NSToolbar alloc] initWithIdentifier:MAIN_TOOLBAR];
[mainToolbar setAllowsUserCustomization:NO];
[mainToolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
[mainToolbar setDelegate:self];
[window setToolbar: mainToolbar];

这些是按钮执行的操作:

-(void)hideToolbar {
    editing = YES;
    [mainToolbar setVisible:NO];
}

-(void)showToolbar {
    editing = NO;
    [mainToolbar setVisible:YES];
}

我尝试使用窗口委托方法修复它,但在进入全屏模式时仍然显示工具栏,无论 editing.

- (void)windowDidEnterFullScreen:(NSNotification *)notification {
  [mainToolbar setVisible:!editing];

感谢

- (void)windowDidExitFullScreen:(NSNotification *)notification {
 [mainToolbar setVisible:!editing];

非常

I am developing an app in which the toolbar can be shown/hide by the user using a button. The problem is the following: If the user chooses to hide the toolbar and then enters the fullscreen mode, the toolbar is shown.

The user interface has been created programmatically (i.e. not using Interface Builder).

This is the toolbar creation in the app delegate:

mainToolbar = [[NSToolbar alloc] initWithIdentifier:MAIN_TOOLBAR];
[mainToolbar setAllowsUserCustomization:NO];
[mainToolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
[mainToolbar setDelegate:self];
[window setToolbar: mainToolbar];

These are the actions performed by the buttons:

-(void)hideToolbar {
    editing = YES;
    [mainToolbar setVisible:NO];
}

-(void)showToolbar {
    editing = NO;
    [mainToolbar setVisible:YES];
}

I have tried to fix it using window delegate methods but still the toolbar is shown when entering full screen mode regardless the value of editing.

- (void)windowDidEnterFullScreen:(NSNotification *)notification {
  [mainToolbar setVisible:!editing];

}

- (void)windowDidExitFullScreen:(NSNotification *)notification {
 [mainToolbar setVisible:!editing];

}

Many thanks in advance!

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

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

发布评论

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

评论(1

惟欲睡 2025-01-12 10:23:16

当窗口全屏显示时,我找不到一种方法来维持工具栏的隐藏/显示状态,但您可以将工具栏设置为始终在全屏模式下隐藏,并在用户转到窗口顶部时以动画显示屏幕。在窗口委托中,您可以设置 NSApplicationPresentationOptions 以返回 NSApplicationPresentationAutoHideToolbar 作为选项之一。我的看起来像这样:

    - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
    return (NSApplicationPresentationFullScreen |       
            NSApplicationPresentationHideDock |         
            NSApplicationPresentationAutoHideMenuBar |
            NSApplicationPresentationAutoHideToolbar);
}

这是相关文档: https:// developer.apple.com/library/mac/#documentation/General/Conceptual/MOSXAppProgrammingGuide/FullScreenApp/FullScreenApp.html

I could not find a way to maintain the hidden/shown state of the toolbar when the window goes full screen, but you can set the toolbar to always be hidden in full screen, and to animate in when the user goes to the top of the screen. In your window delegate, you can set NSApplicationPresentationOptions to return NSApplicationPresentationAutoHideToolbar in as one of the options. Mine looks like this:

    - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
    return (NSApplicationPresentationFullScreen |       
            NSApplicationPresentationHideDock |         
            NSApplicationPresentationAutoHideMenuBar |
            NSApplicationPresentationAutoHideToolbar);
}

Here is the relevant documentation: https://developer.apple.com/library/mac/#documentation/General/Conceptual/MOSXAppProgrammingGuide/FullScreenApp/FullScreenApp.html

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