gpt4 book ai didi

cocoa - OSX El Capitan 上的透明 NSWindow

转载 作者:行者123 更新时间:2023-12-03 16:10:46 25 4
gpt4 key购买 nike

在 El Capitan 之前,这段代码完全按照其应有的方式工作。现在我的窗口不再是透明的,而是白色的。

 NSWindow* window = [[NSWindow alloc] initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO];
[window setOpaque:NO];
[window setBackgroundColor:[NSColor clearColor]];

有什么想法吗?感谢您的帮助。

最佳答案

我不确定您将代码放在哪里,但以下内容对我有用。

  • 创建一个 NSWindow 子类
  • 插入以下代码:

-

- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag {

// Using NSBorderlessWindowMask results in a window without a title bar.
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
if (self != nil) {
// Start with no transparency for all drawing into the window
[self setAlphaValue:1.0];
//Set backgroundColor to clearColor
self.backgroundColor = NSColor.clearColor;
// Turn off opacity so that the parts of the window that are not drawn into are transparent.
[self setOpaque:NO];
}
return self;
}

此代码来自 Apple 示例代码页 - Round Transparent Window

您使用了 NSBackingStoreNonretained 作为窗口背景。根据文档:

You should not use this mode. It exists primarily for use in the original Classic Blue Box. It does not support Quartz drawing, alpha blending, or opacity. Moreover, it does not support hardware acceleration, and interferes with system-wide display acceleration. If you use this mode, your application must manage visibility region clipping itself, and manage repainting on visibility changes.

所以它根本不支持透明窗口。

关于cocoa - OSX El Capitan 上的透明 NSWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33144721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com