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

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

问题描述

将振动暗(NSAppearanceNameVibrantDark)或振动亮(NSAppearanceNameVibrantLight)模式与NSWindow一起使用的正确方法是什么?

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's 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.因此它看起来像[em]正常运行,但是当我的滚动视图滚动其内容(图像的缩略图)时,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天全站免登陆