【发布时间】:2012-02-29 07:34:52
【问题描述】:
我有一个NSWindow 的无边框子类,其中包含带圆角的自定义图形:
我的自定义窗口:
- (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;
}
我的自定义视图:
- (void)drawRect:(NSRect)rect {
[[NSColor clearColor] set];
NSRectFill([self frame]);
[backgroundImage compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];
}
但是,每隔一段时间(可能 10 次中的 1 次),当我启动应用程序时,图形看起来不对,因为我在窗口周围看到一个灰色的 1 像素方形边框。它不是围绕我的自定义图形而是围绕窗口的框架设置的,这意味着它否定了我的圆角。
我的子类中是否缺少某些东西?
编辑: 这是问题的截图:
【问题讨论】:
-
似乎我遇到了同样的问题,我已经解决了。见这里:stackoverflow.com/questions/9124349/…
-
你有没有想过这个问题?我也有同样的问题。
-
对不起山姆,我没有。我最终使用了一种定制化程度较低的设计,其中窗户边缘保持为标准。
标签: objective-c cocoa nswindow