HUD NSPanel 不太透明

发布于 2024-10-27 07:14:03 字数 65 浏览 1 评论 0原文

我一直在网上搜索,但没有遇到更改HUD透明度(所有面板透明度,包括标题栏)的方法。可以改变吗?

谢谢

I've been searching for the web but I have not encountered the way to change the HUD's transparency (ALL the panel transparency, including title bar). It's possible to change it?

Thx

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

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

发布评论

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

评论(3

无人问我粥可暖 2024-11-03 07:14:03

您应该能够使用从 NSWindow 继承的 setAlphaValue

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html

[ myPanel setAlphaValue: 0.5 ];

You should be able to use the setAlphaValue, inherited from NSWindow:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html

[ myPanel setAlphaValue: 0.5 ];
你又不是我 2024-11-03 07:14:03

这是不可能的。 HUD 面板设计为透明;他们不会让你改变他们的不透明度或他们的基本视图的不透明度。

NSLog(@"opaque before? %@", [hud isOpaque] ? @"YES" : @"NO");
[hud setOpaque:YES];
NSLog(@"opaque after? %@", [hud isOpaque] ? @"YES" : @"NO");

OpaqueHUD[18952:a0b] opaque before? NO
OpaqueHUD[18952:a0b] opaque after? NO

NSLog(@"alpha before: %.2f", [hud alphaValue]);
[hud setAlphaValue:1.0f];
NSLog(@"alpha after: %.2f", [hud alphaValue]);

OpaqueHUD[18952:a0b] alpha before: 1.00
OpaqueHUD[18952:a0b] alpha after: 1.00

NSView * contentView = [hud contentView];    
// In layer-backed mode
NSLog(@"content alpha before: %.2f", [contentView alphaValue]);
[contentView setAlphaValue:1.0];
NSLog(@"content alpha after: %.2f", [contentView alphaValue]);

OpaqueHUD[18952:a0b] content alpha before: 1.00
OpaqueHUD[18952:a0b] content alpha after: 1.00

您必须:1)在其中放置一个自定义的不透明子视图并使用半透明的标题栏; b) 使用具有常规样式的 NSPanel,您可以更改其背景颜色和不透明度,并接受它作为常规标题栏;或 d) 创建您自己的自定义窗口(该文章底部另一篇文章的良好链接)。另请参阅这篇关于制作您自己的文章 窗口框架(警告:该框架使用私有 API,并且已有几年历史)。

It's not possible. HUD panels are intended to be transparent; they won't let you change their opacity or the opacity of their base views.

NSLog(@"opaque before? %@", [hud isOpaque] ? @"YES" : @"NO");
[hud setOpaque:YES];
NSLog(@"opaque after? %@", [hud isOpaque] ? @"YES" : @"NO");

OpaqueHUD[18952:a0b] opaque before? NO
OpaqueHUD[18952:a0b] opaque after? NO

NSLog(@"alpha before: %.2f", [hud alphaValue]);
[hud setAlphaValue:1.0f];
NSLog(@"alpha after: %.2f", [hud alphaValue]);

OpaqueHUD[18952:a0b] alpha before: 1.00
OpaqueHUD[18952:a0b] alpha after: 1.00

NSView * contentView = [hud contentView];    
// In layer-backed mode
NSLog(@"content alpha before: %.2f", [contentView alphaValue]);
[contentView setAlphaValue:1.0];
NSLog(@"content alpha after: %.2f", [contentView alphaValue]);

OpaqueHUD[18952:a0b] content alpha before: 1.00
OpaqueHUD[18952:a0b] content alpha after: 1.00

You'll have to: 1) put a custom opaque subview in there and live with a translucent title bar; b) use an NSPanel with the regular style, whose background color and opacity you can change, and live with it being a regular title bar; or d) create your very own custom window (good link to another writeup at the bottom of that article). See also this article about making your own window frame (warning: that one uses private API, and is a few years old).

Spring初心 2024-11-03 07:14:03

这是可能的。您只需要通过在面板视图的核心动画层上设置颜色(包括 Alpha)以编程方式完成此操作。以下是设置透明度稍低的 HUD 面板的示例:

view.layer.backgroundColor = [NSColor colorWithSRGBRed:0.2 green: 0.2 blue: 0.2 alpha:0.7].CGColor

请记住,您必须在视图加载后执行此操作,例如。不要在 init 中设置它:

It is possible. You just need to do it programmatically by setting the color (including alpha) on the Core Animation layer of the panel's view. Here is an example of setting the HUD panel with slightly less transparency:

view.layer.backgroundColor = [NSColor colorWithSRGBRed:0.2 green: 0.2 blue: 0.2 alpha:0.7].CGColor

Just remember that you have to do this after the view has loaded, eg. don't set it in init:

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