我正在尝试制作一个带有圆形视图的透明 NSWindow 。
我正在尝试使用透明窗口获得圆形视图。
这就是它现在的样子:(见角落里的小点)
这是另一个边框半径设置为 10px(在 NSView drawRect 中设置)的示例:
我正在使用此 Apple 示例中的代码:https ://developer.apple.com/library/mac/#samplecode/RoundTransparentWindow/Introduction/Intro.html
特别是我的 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];
// Turn off opacity so that the parts of the window that are not drawn into are transparent.
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
}
return self;
}
这在我的 NSView 子类中:
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor redColor] set];
NSBezierPath* thePath = [NSBezierPath bezierPath];
[thePath appendBezierPathWithRoundedRect:dirtyRect xRadius:3 yRadius:3];
[thePath fill];
}
谁能告诉我我在这里缺少什么?
谢谢。