我有一个无边框的NSWindow
子类,具有自定义图形和圆角:
MyCustomWindow:
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
if (self) {
// Start with no transparency for all drawing into the window
[self setAlphaValue:1.0];
// Turn off opacity so that the parts of the window that are not drawn into are transparent.
[self setOpaque:NO];
[self setMovableByWindowBackground:YES];
}
return self;
}
- (BOOL) canBecomeKeyWindow
{
return YES;
}
MyCustomView:
- (void)drawRect:(NSRect)rect {
[[NSColor clearColor] set];
NSRectFill([self frame]);
[backgroundImage compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];
}
然而,每隔一段时间(大概十次中有一次),当我启动应用程序时,图形看起来不对,因为窗口周围有一个灰色的一个像素的正方形边框。它没有设置在我的自定义图形周围,而是在窗口的框架周围,这意味着它抵消了我的圆角。
我的子类中是否有我遗漏的东西?
编辑: 以下是问题的屏幕截图: