我有下一个问题:
我有NSTextFieldCell
. 在这个子类中,我重写drawWithFrame:
了方法NSCell
并绘制了自定义的半透明视觉表示。这个子类插入到NSTextField
中,插入到半透明视图中。问题来了:绘制代码相互叠加,即Cocoa不断调用drawWithFrame:
方法,不断地将当前绘制结果叠加在之前的绘制结果上。如何避免相互叠加绘图?
有代码:
@interface MySubclass : NSTextFieldCell
...
@end
@implementation
...
// Only this methods overrided
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
[_someGradient drawInRect:cellFrame angle:90]; // gradient alpha is 0.5f
NSBezierPath* path = [NSBezierPath bezierPathWithRect:rect];
[path setClip];
NSShadow* shadow = [[NSShadow new] autorelease];
// setup shadow
[shadow set];
[path stroke];
[_someColor setStroke];
[path stroke];
[super drawWithFrame:cellFrame inView:controlView];
}
...
@end