使用NSBorderlessWindowMask时为灰色边框 [英] Gray border when using NSBorderlessWindowMask
问题描述
每当我尝试使用NSBorderlessWindowMask创建一个自定义窗口,并设置一个NSView(例如一个NSImageView)作为其contentView,我得到一个1px灰色边框周围的NSView,我似乎不能够摆脱它。
Whenever I try to create a custom window using NSBorderlessWindowMask and set an NSView (for example an NSImageView) as its contentView, I get a 1px gray border around the NSView and I don't seem to be able to get rid of it.
我已经遵循了几种方法,包括Apple的RoundTransparentWindow示例代码以及对StackOverflow的几个建议。
I have followed several approaches including Apple's RoundTransparentWindow sample code as well as several suggestions on StackOverflow.
怀疑灰色边框来自窗口本身或NSView。
I suspect the gray border is either coming from the window itself or the NSView.
有任何人遇到过这个问题,或者你有可能的解决方案吗?
Have any of you experienced this problem or do you have a possible solution?
代码相当简单。这是自定义窗口的init方法:
The code is fairly straightforward. This is the init method of the custom window:
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
if (self != nil) {
[self setAlphaValue:1.0];
[self setBackgroundColor:[NSColor clearColor]];
[self setOpaque:NO];
}
return self;
}
要测试这一点,在IB中我放置一个NSImageView在自定义窗口然而NSImageView中的图像有一个边框。这同样适用于其他NSView子类,如NSTextField,NSTableView。
To test this, in IB I place an NSImageView in that custom window WITHOUT border and yet the image in the NSImageView has a border. The same goes for other NSView subclasses, such as NSTextField, NSTableView.
此外,我还注意到,苹果的示例应用程序(RoundTransparentWindow)也发生了同样的情况。是否可以在没有1px边框的自定义窗口中绘制NSView?
In addition, I also noticed that the same is happening with the sample application (RoundTransparentWindow) of Apple. Is it even possible to draw an NSView in a custom window without a 1px border?
感谢
推荐答案
当你使用没有绘图的常规NSView时,你确定会发生这种情况吗?我不打赌。其他控件(如NSImageView)有边框。
Are you sure this happens when you use a regular NSView with no drawing? I bet not. Other controls (like NSImageView)have borders. Maybe you should double check to make sure they're turned off whe possible.
更新 - 如何将视图导入您的窗口?您不包括该代码。我创建了一个基本的测试项目(在这里下载)和一个图像,它的工作原理精细。亲自看看。
Update - How do you get your view into your window? You don't include that code. I created a basic test project (download it here) with an image well and it works just fine. See for yourself.
这篇关于使用NSBorderlessWindowMask时为灰色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!