如何在 NSWindow 中向下移动窗口控件(交通信号灯)?

How can I move window controls (traffic lights) down in an NSWindow?

提问人:Typestuck 提问时间:8/8/2023 最后编辑:NSGodTypestuck 更新时间:10/6/2023 访问量:56

问:

我正在macOS上使用React Native编写应用程序。默认情况下,窗口显示如下:

enter image description here

我已经设法隐藏了标题并使标题栏透明,因此(忽略屏幕截图中的标题):

enter image description here

我现在想将“红绿灯”向下移动/设置工具栏样式以匹配如下所示的样式:

enter image description here

不幸的是,我似乎无法弄清楚执行此操作所需的设置组合。

我只能扩展 objective-c AppDelegate 实现。我有当前的代码;

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
  NSWindow *window = [[NSApplication sharedApplication] mainWindow];
  window.titleVisibility = NSWindowTitleHidden;
  window.titlebarAppearsTransparent = true;
  window.styleMask |= NSWindowStyleMaskFullSizeContentView;
}

这适用于进入第二阶段。我尝试过诸如 ;

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
  NSWindow *window = [[NSApplication sharedApplication] mainWindow];
  window.titleVisibility = NSWindowTitleHidden;
  window.titlebarAppearsTransparent = true;
  window.styleMask |= NSWindowStyleMaskFullSizeContentView;
  NSToolbar *toolbar = [NSToolbar init];
  window.toolbar = toolbar;
}

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
  NSWindow *window = [[NSApplication sharedApplication] mainWindow];
  window.titleVisibility = NSWindowTitleHidden;
  window.titlebarAppearsTransparent = true;
  window.styleMask |= NSWindowStyleMaskFullSizeContentView;
  window.toolbarStyle = NSWindowToolbarStyleUnified;
}

和其他变体,但无济于事。toolbarStyle

Objective-C React-Native Cocoa Appkit nsWindow

评论


答:

0赞 jnpdx 10/6/2023 #1

以下代码对我有用:

- (void)applicationWillBecomeActive:(NSNotification *)notification
{
    NSWindow *window = [[[NSApplication sharedApplication] windows] firstObject];
    window.titleVisibility = NSWindowTitleHidden;
    window.titlebarAppearsTransparent = true;
    window.styleMask |= NSWindowStyleMaskFullSizeContentView;
    window.toolbar = [NSToolbar new]; // <-- Note this is `new` and not `init`
    window.toolbarStyle = NSWindowToolbarStyleUnified;
}

enter image description here