모양을 그려야하고 그 위에 작은 투명 모양을 그렸습니다. NSWindow에서 블랙홀/패치가 발생하는 합성 드로잉 모드 설정하기
-(void) drawRect:(NSRect)dirtyRect
{
//clear everything
{
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
}
NSBezierPath *thePath = [NSBezierPath bezierPathWithOvalInRect: self.bounds];
[thePath setLineWidth: 30];
[[NSColor blueColor] set];
[thePath stroke];
[[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeCopy];
[[NSColor clearColor] set];
[thePath setLineWidth: 4];
[thePath stroke];
}
-(void) drawRect:(NSRect)dirtyRect
{
//clear everything
{
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
}
NSImage* image = [[NSImage alloc] initWithSize:self.frame.size];
[image lockFocus];
//clear everything
{
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
}
NSBezierPath *thePath = [NSBezierPath bezierPathWithOvalInRect: self.bounds];
[thePath setLineWidth: 30];
[[NSColor blueColor] set];
[thePath stroke];
[[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeCopy];
[[NSColor clearColor] set];
[thePath setLineWidth: 4];
[thePath stroke];
[image unlockFocus];
[image drawInRect:self.frame fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
}
멋진 설명을 가져 주셔서 감사합니다. 솔리드 모양 위에 투명 모양을 그리는 방법이 있는지, 결과에 창 그림자 나 블랙홀이 표시되어서는 안된다는 사실을 알고 싶었습니다. – Omkar
@Omkar : "투명"과 "창 그림자를 표시하면 안됩니다"는 투명성 때문에 투명도는 창 뒤의 내용을 볼 수있게하고 그림자는 창 뒤에 있습니다. 창 그림자를 끌 수는 있지만 창 주위에는 보이지 않습니다. –