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

vx6bjr1n  于 2023-10-22  发布在  React
关注(0)|答案(1)|浏览(131)

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

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

我现在想移动'交通灯'下来/设置工具栏样式,以匹配如下所示的样式:

不幸的是,我似乎无法找出设置的组合或这样做所需的。
我不得不扩展一个objective-cAppDelegate实现。我有当前代码;

- (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的其它变体,但都无济于事。

suzh9iv8

suzh9iv81#

以下代码适用于我:

- (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;
}

相关问题