开发者

Stopping transparent drawing going all the way through NSViews

开发者 https://www.devze.com 2023-02-22 09:17 出处:网络
I\'m doing some simple drawing in my NSView\'s drawRect with code like this [[NSColor colorWithCalibratedWhite:0.250 alpha:0.700] set];

I'm doing some simple drawing in my NSView's drawRect with code like this

[[NSColor colorWithCalibratedWhite:0.250 alpha:0.700] set];
NSRectFill(dRect);

This drawing is being done in a nested view and I'm finding that the transparency goes all the way through the parent view and w开发者_如何学编程indow showing some of the screen beneath it.

How do I get it so the transparency only goes through to the parent view (or any drawing that was done in that frame before it?

Thanks!


You really shouldn't be using NSRectFill to draw a transparent color. A call to

NSRectFill(rect);

is really just a shortcut to

NSRectFillUsingOperation(rect, NSCompositeCopy);

NSCompositeCopy doesn't perform compositing, so you can get unexpected results when a transparent NSColor is set.

Try using this instead:

[[NSColor colorWithCalibratedWhite:0.250 alpha:0.700] set];
[NSBezierPath fillRect:rect];

That should draw the transparency properly, with the underlying drawing visible.

0

精彩评论

暂无评论...
验证码 换一张
取 消