我正在尝试使用 Cocoa 绘制形状的反射。我已经应用了一个 NSAffineTransform 并成功地重绘了形状,但现在我不知道如何在它上面绘制一个 alpha 蒙版。我正在使用一个NSCompositeDestinationOut
操作,但它给了我一个不需要的结果:alt text http://img687.imageshack.us/img687/2417/capturdcran20100623094.png
我不完全确定如何解决这个问题 - 我需要这样做,以便渐变仅充当 alpha 蒙版并且实际上不显示。我是否使用了错误的合成模式?
谢谢!如果需要,这是渐变代码:
- (void)fadeOutRect:(NSRect)rect {
[NSGraphicsContext saveGraphicsState];
[[NSGraphicsContext currentContext] setCompositingOperation:NSCompositeDestinationOut];
NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations:
[[NSColor blackColor] colorWithAlphaComponent:0.5], 0.0,
[[NSColor blackColor] colorWithAlphaComponent:1.0], 0.8, nil];
[gradient drawInRect:NSMakeRect(rect.origin.x, rect.origin.y + rect.size.height - ( PILL_HEIGHT * 2 ),
rect.size.width, PILL_HEIGHT) angle:270];
[NSGraphicsContext restoreGraphicsState];
}