你如何在 NSWindow 上使用黑暗的活力? [英] How do you use the dark vibrancy on an NSWindow?

查看:27
本文介绍了你如何在 NSWindow 上使用黑暗的活力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSWindow 中使用 Vibrant Dark (NSAppearanceNameVibrantDark) 或 Vibrant Light (NSAppearanceNameVibrantLight) 模式的正确方法是什么?

What is the correct way to use the Vibrant Dark (NSAppearanceNameVibrantDark) or Vibrant Light (NSAppearanceNameVibrantLight) modes with an NSWindow?

我正在构建一个应用程序,并希望提供新的 Vibrant Dark 外观作为主应用程序 NSWindow 的一个选项.窗口本身是一个非常直接的窗口,顶部有一个 NSToolbar,滚动视图作为主要内容区域.

I'm building an application and would like to offer the new Vibrant Dark appearance as an option for the main application's NSWindow. The window itself is a pretty straight forward window with an NSToolbar across the top and a scroll view as the main content area.

Apple 提供了大量关于将新的活力外观与 NSVisualEffectsView 结合使用的信息,但我正在寻找有关如何在 NSWindow 上使用这些外观的说明>.

There's plenty of information from Apple on using the new vibrancy appearances in conjunction with an NSVisualEffectsView, but I'm looking for clarification on how to use those appearances on an NSWindow.

NSAppearance.h 头文件中,有一条注释指出,只有在NSVisualEffectsView 上才能设置充满活力的外观.没有提到 NSWindow 支持它.

In the NSAppearance.h header file, there's a comment that states that the vibrant appearances should only be set on an NSVisualEffectsView. There's no mention of it being supported on NSWindow.

WWDC 视频谈到确保您使用层支持的视图,并且在使用新的充满活力的外观时允许您的子视图充满活力,但同样,没有提到在 NSWindow 上使用它们.

The WWDC videos talk about making sure that you're using layer-backed views and that you're allowing vibrancy on your subviews when using the new vibrant appearances, but again, no mention of using them on an NSWindow.

VisualEffectsPlayground 示例代码确实有一个类似 Facetime 的应用程序示例,该应用程序使用深色活力模式,但它没有工具栏,而是使用完整内容蒙版.

The VisualEffectsPlayground sample code does have an example of a Facetime-like application that uses the dark vibrancy mode, but it doesn't have a toolbar and it uses the full-content mask.

根据这些信息,我在我的 NSWindowController 的 windowDidLoad 方法中执行以下操作:

From that information, I'm doing the following in my NSWindowController's windowDidLoad method:

[self.window.contentView setWantsLayer:YES];
self.window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark];

而且,果然,我得到了一个带有黑色窗口标题栏的黑色 NSToolbar.所以它看起来工作正常,但是当我的滚动视图滚动其内容(图像缩略图)时,NSToolbar 下的标准半透明和窗口的标题栏要么不存在,要么是随机出现的.似乎没有任何模式.有时,当我滚动滚动视图时,工具栏和标题栏下的内容显示为模糊"状态.其他时候当我滚动时,工具栏和标题栏只是一个不透明的黑色.(标题栏和工具栏仍然绘制它们的标题和按钮.)

And, sure enough, I get a black NSToolbar with a black window title bar. So it looks like it's working properly, but when my scrollview scrolls its content (thumbnails of images) the standard translucency under the NSToolbar and the window's title bar is either not present or is randomly present. There doesn't seem to be any pattern. Sometimes when I scroll the scrollview, the content is shown in the "blurred" state under the toolbar and title bar. Other times when I scroll, the toolbar and titlebar are just an opaque black. (The title bar and toolbar still draw their titles and buttons.)

当我不为窗口的内容视图请求图层时,我会得到更多的灰色标题栏和窗口标题,而不是纯"黑色的.(我的滚动视图的背景颜色可以是白色、深灰色或黑色.)

When I don't request a layer for the window's content view, then I get more a gray titlebar and window title rather than a "pure" black one. (My scrollview's background color can be either white, dark gray or black.)

有关如何正确配置 NSWindow(包含 NSToolbarNSScollView)以使用新的活力外观的任何帮助或说明将不胜感激.

Any help or clarification on how to properly configure an NSWindow (that contains an NSToolbar and an NSScollView) to use the new vibrancy appearances would be much appreciated.

推荐答案

这将创建一个暗模式窗口.随后,窗口中的所有内容(包括标题栏、工具栏甚至对话表)都会变暗.

This will make a dark mode window. Subsequently, everything in the window (including titlebar, toolbar and even dialogue sheets) will become dark.

    let USE_DARK_MODE = true
    if USE_DARK_MODE {
        window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
        window.invalidateShadow()
    }

invalidateShadow 似乎不是必需的,但有时如果缺少阴影,则阴影无法正常工作.(OS X 10.10)

invalidateShadow doesn't seem required, but sometimes shadow does not work properly if lacked. (OS X 10.10)

这篇关于你如何在 NSWindow 上使用黑暗的活力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆